diff options
author | Lee Duncan <lduncan@suse.com> | 2021-01-04 16:33:40 -0800 |
---|---|---|
committer | Lee Duncan <lduncan@suse.com> | 2021-01-04 16:33:40 -0800 |
commit | 8570399b5c6c2a484ff3bf22043c9023a968d058 (patch) | |
tree | f128ba0b45b3b3ff0a37df65300d3165db5693c6 | |
parent | 34e3ffb194f6fa3028c0eb2ff57e7db2d1026771 (diff) | |
download | open-iscsi-8570399b5c6c2a484ff3bf22043c9023a968d058.tar.gz |
iscsid: Do not allow conflicting pid-file options
The daemon allowed both the no-pid-file option and specifying
a PID file to use, and honored which ever option was supplied
last. This commmit ensures non-conflicting options are supplied.
-rw-r--r-- | doc/iscsid.8 | 23 | ||||
-rw-r--r-- | usr/iscsid.c | 19 |
2 files changed, 31 insertions, 11 deletions
diff --git a/doc/iscsid.8 b/doc/iscsid.8 index 6f9218f..db996b4 100644 --- a/doc/iscsid.8 +++ b/doc/iscsid.8 @@ -24,23 +24,28 @@ Read initiator name from \fIiname\-file\fR rather than the default .BI [-f|--foreground] run .B iscsid -in the foreground. +in the foreground. Implies +.BR --no-pid-file . .TP -.BI [-d|--debug=]\fIdebug_level\fP +.BI [-d|--debug=] debug_level print debugging information. Valid values for debug_level are 0 to 8. .TP -.BI [-u|--uid=]\fIuid\fP -run under user ID \fIuid\fR (default is the current user ID) +.BI [-u|--uid=] uid +run under user ID \fIuid\fR (default is the current user ID). .TP -.BI [-g|--gid=]\fIgid\fP +.BI [-g|--gid=] gid run under user group ID \fIgid\fR (default is the current user group ID). .TP -.BI [-n|--no-pid-file]\fP -do not write a process ID file. +.BI [-n|--no-pid-file] +do not write a process ID file. Conflicts with the +.BI --pid= +option. .TP -.BI [-p|--pid=]\fIpid\-file\fP +.BI [-p|--pid=] pid\-file write process ID to \fIpid\-file\fR rather than the default -\fI/run/iscsid.pid\fR +\fI/run/iscsid.pid\fR. Conflicts with the +.BI --no-pid-file +option. .TP .BI [-h|--help] display this help and exit diff --git a/usr/iscsid.c b/usr/iscsid.c index 3544870..6b46f8f 100644 --- a/usr/iscsid.c +++ b/usr/iscsid.c @@ -63,7 +63,7 @@ struct iscsi_daemon_config *dconfig = &daemon_config; static char program_name[] = "iscsid"; static pid_t log_pid; static gid_t gid; -static int daemonize = 1; +static bool daemonize = true; static int mgmt_ipc_fd; static int sessions_to_recover = 0; @@ -381,6 +381,8 @@ int main(int argc, char *argv[]) struct sigaction sa_new; int control_fd; pid_t pid; + bool pid_file_specified = false; + bool no_pid_file_specified = false; while ((ch = getopt_long(argc, argv, "c:i:fd:nu:g:p:vh", long_options, &longindex)) >= 0) { @@ -392,7 +394,7 @@ int main(int argc, char *argv[]) initiatorname_file = optarg; break; case 'f': - daemonize = 0; + daemonize = false; break; case 'd': log_level = atoi(optarg); @@ -405,9 +407,11 @@ int main(int argc, char *argv[]) break; case 'n': pid_file = NULL; + no_pid_file_specified = true; break; case 'p': pid_file = optarg; + pid_file_specified = true; break; case 'v': printf("%s version %s\n", program_name, @@ -422,6 +426,17 @@ int main(int argc, char *argv[]) } } + if (pid_file_specified) { + if (no_pid_file_specified) { + fprintf(stderr, "error: Conflicting PID-file options requested\n"); + usage(1); + } + if (!daemonize) { + fprintf(stderr, "error: PID file specified but unused in foreground mode\n"); + usage(1); + } + } + /* initialize logger */ log_pid = log_init(program_name, DEFAULT_AREA_SIZE, daemonize ? log_do_log_daemon : log_do_log_std, NULL); |