From a2521f5b0ae2b82145dd6ea5be69810e2b89754d Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Sun, 21 Jan 2007 08:02:44 +0000 Subject: [PATCH] If it doesn't exist, only error if requested. git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2466 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- scripts/vserver.start | 4 ++-- src/vsysctl.c | 24 +++++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/scripts/vserver.start b/scripts/vserver.start index 7dda3e6..c602d4e 100644 --- a/scripts/vserver.start +++ b/scripts/vserver.start @@ -136,8 +136,8 @@ if $_VSERVER_INFO - FEATURE migrate; then ${USE_VNAMESPACE:+$_VNAMESPACE --set -- } \ $_VLIMIT --dir "$VSERVER_DIR"/rlimits --missingok -- \ $_VSCHED --xid self --force "${OPTS_VSCHED[@]}" -- \ - $_VSYSCTL --xid self --dir "$VSERVER_DIR"/sysctl -- \ - $_VUNAME --xid self --dir "$VSERVER_DIR"/uts --missingok -- \ + $_VSYSCTL --xid self --dir "$VSERVER_DIR"/sysctl --missingok -- \ + $_VUNAME --xid self --dir "$VSERVER_DIR"/uts --missingok -- \ "${VSERVER_EXTRA_CMDS[@]}" \ $_VUNAME --xid self --set -t context="$VSERVER_DIR" -- \ $_VATTRIBUTE --set "${OPTS_VATTRIBUTE[@]}" -- \ 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); } -- 1.8.1.5