X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvsysctl.c;h=ca022a14d804b4035297b7f23f755e6fdaaca311;hb=78026d29e4fd0c0b70845cb96d682e9061c3a261;hp=7f6f1ddbb480738de72ee8d580e46b6ffaece42c;hpb=6ca5817232cc9d844f142ce9c300a4206f43867a;p=util-vserver.git diff --git a/src/vsysctl.c b/src/vsysctl.c index 7f6f1dd..ca022a1 100644 --- a/src/vsysctl.c +++ b/src/vsysctl.c @@ -48,6 +48,7 @@ #define CMD_VERSION 0x1001 #define CMD_XID 0x4000 #define CMD_DIR 0x4001 +#define CMD_MISSINGOK 0x4002 int wrapper_exit_code = 1; @@ -57,6 +58,7 @@ CMDLINE_OPTIONS[] = { { "version", no_argument, 0, CMD_VERSION }, { "xid", required_argument, 0, CMD_XID }, { "dir", required_argument, 0, CMD_DIR }, + { "missingok", no_argument, 0, CMD_MISSINGOK }, {0,0,0,0} }; @@ -66,7 +68,7 @@ showHelp(int fd, char const *cmd) WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, - " --xid --dir -- *\n" + " --xid --dir [--missingok] -- *\n" "\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); @@ -128,6 +130,7 @@ int main(int argc, char *argv[]) { xid_t xid = VC_NOCTX; const char *dir = NULL; + bool missing = false; while (1) { int c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0); @@ -138,6 +141,7 @@ int main(int argc, char *argv[]) case CMD_VERSION : showVersion(); case CMD_XID : xid = Evc_xidopt2xid(optarg, true); break; case CMD_DIR : dir = optarg; break; + case CMD_MISSINGOK: missing = true; break; default : WRITE_MSG(2, "Try '"); @@ -155,13 +159,19 @@ int main(int argc, char *argv[]) Echdir(PROC_SYS_DIRECTORY); - dp = Eopendir(dir); - while ((de = Ereaddir(dp)) != NULL) { - if (*de->d_name == '.') - continue; - handle_setting(dir, de->d_name); + dp = opendir(dir); + if (dp != NULL) { + while ((de = Ereaddir(dp)) != NULL) { + if (*de->d_name == '.') + continue; + handle_setting(dir, de->d_name); + } + Eclosedir(dp); + } + else if (!missing) { + perror(ENSC_WRAPPERS_PREFIX "opendir"); + exit(wrapper_exit_code); } - Eclosedir(dp); Efchdir(curdir); }