Репозиторий ALT Linux backports/2.4
Последнее обновление: 9 июля 2008 | Пакетов: 497 | Посещений: 1584000
 поиск   регистрация   авторизация 
 
Группа :: Система/Серверы
Пакет: unfs3

 Главная   Изменения   Спек   Патчи   Загрузить   Bugs and FR 

Патч: unfs3-pidfile.patch


Index: CREDITS
===================================================================
RCS file: /cvsroot/unfs3/unfs3/CREDITS,v
retrieving revision 1.11
diff -u -5 -p -u -r1.11 CREDITS
--- CREDITS	4 Jan 2007 19:36:00 -0000	1.11
+++ CREDITS	26 Jan 2007 22:25:07 -0000
@@ -23,5 +23,7 @@ People who contributed ideas, suggestion
 - Constantin Scheder <scheder@nirvanastorage.com>
 - Sam Sharma <sam.sharma@gat.com>
 - Holger Wolf <Holger.Wolf@de.ibm.com>
 - Frank v Waveren <fvw@var.cx>
 - Matthew Bloch <matthew@bytemark.co.uk>
+- Anton Farygin <rider@altlinux.com>
+- Michael Shigorin <mike@osdn.org.ua>
Index: NEWS
===================================================================
RCS file: /cvsroot/unfs3/unfs3/NEWS,v
retrieving revision 1.47
diff -u -5 -p -u -r1.47 NEWS
--- NEWS	22 Jan 2007 12:45:08 -0000	1.47
+++ NEWS	26 Jan 2007 22:25:07 -0000
@@ -1,15 +1,22 @@
 What's new or changed in 0.9.18
 ===============================
 
+The daemon can now be instructed to write its pid (process id) to
+a file by use of the new -i command line option. The feature was
+originally written as an ALT Linux patch to unfs3 created by
+Anton Farygin and then ported to unfs3 0.9.17 by Michael Shigorin.
+The official implementation of the feature is based on their work.
 
 
 ChangeLog
 =========
 
 Version 0.9.18
 
+  - add support for writing a pid file with the -i option
+
 Version 0.9.17
 
   - add support for 64 bit inode numbers
   - the returned "fileid" is now equal to the file's real inode number
   - fix ACCESS and read_executable to stop adding permissions when user or 
Index: backend_unix.h
===================================================================
RCS file: /cvsroot/unfs3/unfs3/backend_unix.h,v
retrieving revision 1.6
diff -u -5 -p -u -r1.6 backend_unix.h
--- backend_unix.h	5 Jan 2007 15:08:12 -0000	1.6
+++ backend_unix.h	26 Jan 2007 22:25:07 -0000
@@ -66,7 +66,9 @@
 #define backend_fsinfo_properties FSF3_LINK | FSF3_SYMLINK | FSF3_HOMOGENEOUS | FSF3_CANSETTIME;
 #define backend_pathconf_case_insensitive FALSE
 #define backend_passwdstruct struct passwd
 #define backend_getpwnam getpwnam
 #define backend_gen_nonce gen_nonce
+#define backend_flock flock
+#define backend_getpid getpid
 
 #endif
Index: backend_win32.h
===================================================================
RCS file: /cvsroot/unfs3/unfs3/backend_win32.h,v
retrieving revision 1.2
diff -u -5 -p -u -r1.2 backend_win32.h
--- backend_win32.h	5 Jan 2007 15:08:12 -0000	1.2
+++ backend_win32.h	26 Jan 2007 22:25:07 -0000
@@ -65,7 +65,9 @@
 #define backend_dirstream UNFS3_WIN_DIR
 #define backend_fsinfo_properties FSF3_HOMOGENEOUS | FSF3_CANSETTIME;
 #define backend_pathconf_case_insensitive TRUE
 #define backend_getpwnam(name) NULL
 #define backend_gen_nonce win_gen_nonce
+#define backend_flock flock
+#define backend_getpid getpid
 
 #endif
Index: daemon.c
===================================================================
RCS file: /cvsroot/unfs3/unfs3/daemon.c,v
retrieving revision 1.61
diff -u -5 -p -u -r1.61 daemon.c
--- daemon.c	22 Jan 2007 12:45:08 -0000	1.61
+++ daemon.c	26 Jan 2007 22:25:08 -0000
@@ -6,10 +6,11 @@
  * see file LICENSE for license details
  */
 
 #include "config.h"
 
+#include <sys/file.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <rpc/rpc.h>
 #include <rpc/pmap_clnt.h>
 
@@ -67,10 +68,11 @@ unsigned int opt_nfs_port = NFS_PORT;	/*
 unsigned int opt_mount_port = NFS_PORT;
 int opt_singleuser = FALSE;
 int opt_brute_force = FALSE;
 struct in_addr opt_bind_addr;
 int opt_readable_executables = FALSE;
+char *opt_pid_file = NULL;
 
 /* Register with portmapper? */
 int opt_portmapper = TRUE;
 
 /*
@@ -132,16 +134,64 @@ int get_socket_type(struct svc_req *rqst
 
     return v;
 }
 
 /*
+ * write current pid to a file
+ */
+static void create_pid_file(void)
+{
+    char buf[16];
+    int fd, res, len;
+    
+    if (!opt_pid_file) return;
+    
+    fd = backend_open_create(opt_pid_file, O_RDWR | O_CREAT | O_TRUNC, 0644);
+    if (fd == -1) {
+        logmsg(LOG_WARNING, "failed to create pid file `%s'", opt_pid_file);
+        return;
+    }
+    
+    res = backend_flock(fd, LOCK_EX | LOCK_NB);
+    if (res == -1) {
+        logmsg(LOG_WARNING, "failed to lock pid file `%s'", opt_pid_file);
+        backend_close(fd);
+        return;
+    }
+    
+    sprintf(buf, "%i\n", backend_getpid());
+    len = strlen(buf);
+
+    res = backend_pwrite(fd, buf, len, 0);
+    backend_close(fd);
+    if (res != len) {
+        logmsg(LOG_WARNING, "failed to write pid file `%s'", opt_pid_file);
+    }
+}
+
+/*
+ * remove pid file
+ */
+static void remove_pid_file(void)
+{
+    int res;
+
+    if (!opt_pid_file) return;
+  
+    res = backend_remove(opt_pid_file);
+    if (res == -1 && errno != ENOENT) {
+        logmsg(LOG_WARNING, "failed to remove pid file `%s'", opt_pid_file);
+    }
+}
+
+/*
  * parse command line options
  */
 static void parse_options(int argc, char **argv)
 {
     int opt = 0;
-    char *optstring = "bcC:de:hl:m:n:prstuw";
+    char *optstring = "bcC:de:hl:m:n:prstuwi:";
 
     while (opt != -1) {
 	opt = getopt(argc, argv, optstring);
 	switch (opt) {
 	    case 'b':
@@ -175,10 +225,11 @@ static void parse_options(int argc, char
 		printf("Usage: %s [options]\n", argv[0]);
 		printf("\t-h          display this short option summary\n");
 		printf("\t-u          use unprivileged port for services\n");
 		printf("\t-d          do not detach from terminal\n");
 		printf("\t-e <file>   file to use instead of /etc/exports\n");
+		printf("\t-i <file>   write daemon pid to given file\n");
 #ifdef WANT_CLUSTER
 		printf("\t-c          enable cluster extensions\n");
 		printf("\t-C <path>   set path for cluster extensions\n");
 #endif
 		printf("\t-n <port>   port to use for NFS service\n");
@@ -237,10 +288,13 @@ static void parse_options(int argc, char
 		break;
 	    case 'u':
 		opt_nfs_port = 0;
 		opt_mount_port = 0;
 		break;
+            case 'i':
+                opt_pid_file = optarg;
+                break;
 	    case '?':
 		exit(1);
 		break;
 	}
     }
@@ -286,10 +340,11 @@ void daemon_exit(int error)
     fd_cache_purge();
 
     if (opt_detach)
 	closelog();
 
+    remove_pid_file();
     backend_shutdown();
 
     exit(1);
 }
 
@@ -860,10 +915,13 @@ int main(int argc, char **argv)
 	}
 #endif				       /* WIN32 */
 
 	/* no umask to not screw up create modes */
 	umask(0);
+	
+	/* create pid file if wanted */
+	create_pid_file();
 
 	/* initialize internal stuff */
 	fh_cache_init();
 	fd_cache_init();
 	get_squash_ids();
Index: unfsd.8
===================================================================
RCS file: /cvsroot/unfs3/unfs3/unfsd.8,v
retrieving revision 1.22
diff -u -5 -p -u -r1.22 unfsd.8
--- unfsd.8	17 Jan 2007 07:15:08 -0000	1.22
+++ unfsd.8	26 Jan 2007 22:25:08 -0000
@@ -78,10 +78,16 @@ Display a short option summary.
 .BI "\-e " "\<file\>"
 Use the given file as the exports file, instead of using
 .IR /etc/exports .
 Note that the file needs to be specified using an absolute path.
 .TP
+.BI "\-i " "\<file\>"
+Use the given file as pid file. When the daemon starts up, it will
+write its pid (process id) to the given file. Upon exit, the daemon
+will remove the file. Failure to create or remove the pid file is
+not considered fatal and only reported to syslog.
+.TP
 .B \-u
 Use an unprivileged port for NFS and MOUNT service. Normally,
 .B unfsd
 will use port number 2049, which is the standard port for NFS.
 When this option is in effect, arbitrary ports chosen by the RPC library
 
design & coding: Vladimir Lettiev aka crux © 2004-2005