summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/iscsid.83
-rw-r--r--usr/iscsid.c40
2 files changed, 27 insertions, 16 deletions
diff --git a/doc/iscsid.8 b/doc/iscsid.8
index 1dfa1e5..92b7f81 100644
--- a/doc/iscsid.8
+++ b/doc/iscsid.8
@@ -35,6 +35,9 @@ run under user ID \fIuid\fR (default is the current user ID)
.BI [-g|--gid=]\fIgid\fP
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.
+.TP
.BI [-p|--pid=]\fIpid\-file\fP
write process ID to \fIpid\-file\fR rather than the default
\fI/var/run/iscsid.pid\fR
diff --git a/usr/iscsid.c b/usr/iscsid.c
index 3fa3295..1a37347 100644
--- a/usr/iscsid.c
+++ b/usr/iscsid.c
@@ -69,6 +69,7 @@ static struct option const long_options[] = {
{"debug", required_argument, NULL, 'd'},
{"uid", required_argument, NULL, 'u'},
{"gid", required_argument, NULL, 'g'},
+ {"no-pid-file", no_argument, NULL, 'n'},
{"pid", required_argument, NULL, 'p'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
@@ -90,6 +91,7 @@ Open-iSCSI initiator daemon.\n\
-d, --debug debuglevel print debugging information\n\
-u, --uid=uid run as uid, default is current user\n\
-g, --gid=gid run as gid, default is current user group\n\
+ -n, --no-pid-file do not use a pid file\n\
-p, --pid=pidfile use pid file (default " PID_FILE ").\n\
-h, --help display this help and exit\n\
-v, --version display version and exit\n\
@@ -339,7 +341,7 @@ int main(int argc, char *argv[])
int control_fd;
pid_t pid;
- while ((ch = getopt_long(argc, argv, "c:i:fd:u:g:p:vh", long_options,
+ while ((ch = getopt_long(argc, argv, "c:i:fd:nu:g:p:vh", long_options,
&longindex)) >= 0) {
switch (ch) {
case 'c':
@@ -360,6 +362,9 @@ int main(int argc, char *argv[])
case 'g':
gid = strtoul(optarg, NULL, 10);
break;
+ case 'n':
+ pid_file = NULL;
+ break;
case 'p':
pid_file = optarg;
break;
@@ -415,13 +420,15 @@ int main(int argc, char *argv[])
if (daemonize) {
char buf[64];
- int fd;
-
- fd = open(pid_file, O_WRONLY|O_CREAT, 0644);
- if (fd < 0) {
- log_error("Unable to create pid file");
- log_close(log_pid);
- exit(ISCSI_ERR);
+ int fd = -1;
+
+ if (pid_file) {
+ fd = open(pid_file, O_WRONLY|O_CREAT, 0644);
+ if (fd < 0) {
+ log_error("Unable to create pid file");
+ log_close(log_pid);
+ exit(ISCSI_ERR);
+ }
}
pid = fork();
if (pid < 0) {
@@ -439,15 +446,16 @@ int main(int argc, char *argv[])
}
chdir("/");
- if (lockf(fd, F_TLOCK, 0) < 0) {
- log_error("Unable to lock pid file");
- log_close(log_pid);
- exit(ISCSI_ERR);
+ if (fd > 0) {
+ if (lockf(fd, F_TLOCK, 0) < 0) {
+ log_error("Unable to lock pid file");
+ log_close(log_pid);
+ exit(ISCSI_ERR);
+ }
+ ftruncate(fd, 0);
+ sprintf(buf, "%d\n", getpid());
+ write(fd, buf, strlen(buf));
}
- ftruncate(fd, 0);
- sprintf(buf, "%d\n", getpid());
- write(fd, buf, strlen(buf));
-
daemon_init();
} else {
if ((control_fd = ipc->ctldev_open()) < 0) {