Antw: [PATCH 3/8] iscsid: Implement --no-pid-file

2011-06-24 Thread Ulrich Windl

[...]
> diff --git a/usr/iscsid.c b/usr/iscsid.c
> index 3fa3295..1a37347 100644
> --- a/usr/iscsid.c
> +++ b/usr/iscsid.c
[...]
> @@ -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,

I usually prefer to have the options letters sorted by alphabet. So you can 
easily find out which letters are used already.

>&longindex)) >= 0) {
>   switch (ch) {
>   case 'c':
[...]

Ulrich


-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-iscsi@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.



[PATCH 3/8] iscsid: Implement --no-pid-file

2011-06-21 Thread Hannes Reinecke
For root on iSCSI scenarios the /var directory might not exist.
And we don't need the pid file anyway as the daemon is synchronized
via the IPC connection.

Signed-off-by: Hannes Reinecke 
---
 doc/iscsid.8 |3 +++
 usr/iscsid.c |   40 
 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) {
-- 
1.7.3.4

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-iscsi@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.



PID file

2008-07-05 Thread Martha Flock

Hi,

I noticed that iscsid does not delete its PID-file /var/run/iscsid.pid
when it is stopped, should be changed!


Best regards,

Martha

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-iscsi@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/open-iscsi
-~--~~~~--~~--~--~---