[Fakeroot-commits] [SCM] fakeroot branch, upstream, updated. debian/1.14.3-200-gb232f8a

Timo Savola tsavola at movial.fi
Tue Aug 23 13:05:32 UTC 2011


The following commit has been merged in the upstream branch:
commit d2e7e5cb503016d4266619e3b1de3a688eaa6140
Author: Timo Savola <tsavola at movial.fi>
Date:   Fri Jan 21 09:09:30 2005 +0000

    Clean up #ifdefs
    
    Rearranged FAKEROOT_FAKENET #ifdefs so that communication.c and faked.c
    are manageable again.
    
    git-archimport-id: fakeroot at packages.debian.org--fakeroot/fakeroot--main--0.0--patch-46

diff --git a/communicate.c b/communicate.c
index 668e2ba..ec66b0c 100644
--- a/communicate.c
+++ b/communicate.c
@@ -17,7 +17,15 @@
 # include <sys/ipc.h>
 # include <sys/msg.h>
 # include <sys/sem.h>
-#endif /* ! FAKEROOT_FAKENET */
+#else /* FAKEROOT_FAKENET */
+# include <netinet/in.h>
+# include <netinet/tcp.h>
+# include <netdb.h>
+# include <pthread.h>
+# ifdef HAVE_ENDIAN_H
+#  include <endian.h>
+# endif
+#endif /* FAKEROOT_FAKENET */
 #include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
@@ -29,20 +37,6 @@
 # include <sys/socket.h>
 #endif
 
-#ifndef FAKEROOT_FAKENET
-int msg_snd=-1;
-int msg_get=-1;
-int sem_id=-1;
-#else /* FAKEROOT_FAKENET */
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <netdb.h>
-#include <pthread.h>
-#ifdef HAVE_ENDIAN_H
-# include <endian.h>
-#endif
-#endif /* FAKEROOT_FAKENET */
-
 
 #ifndef _UTSNAME_LENGTH
 /* for LINUX libc5 */
@@ -50,11 +44,17 @@ int sem_id=-1;
 #endif
 
 
-#ifdef FAKEROOT_FAKENET
+#ifndef FAKEROOT_FAKENET
+int msg_snd=-1;
+int msg_get=-1;
+int sem_id=-1;
+#else /* FAKEROOT_FAKENET */
 static int comm_sd = -1;
 static pthread_mutex_t comm_sd_mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif /* FAKEROOT_FAKENET */
 
 
+#ifdef FAKEROOT_FAKENET
 static void fail(const char *msg)
 {
   if (errno > 0)
@@ -64,9 +64,8 @@ static void fail(const char *msg)
 
   exit(1);
 }
-
-
 #endif /* FAKEROOT_FAKENET */
+
 const char *env_var_set(const char *env){
   const char *s;
   
@@ -206,6 +205,7 @@ void stat32from64(struct stat *s32, const struct stat64 *s64)
 #endif
 
 #ifndef FAKEROOT_FAKENET
+
 void semaphore_up(){
   struct sembuf op;
   if(sem_id==-1)
@@ -223,7 +223,30 @@ void semaphore_up(){
     } else {
       break;
     }
+  }
+}
+
+void semaphore_down(){
+  struct sembuf op;
+  if(sem_id==-1)
+    sem_id=semget(get_ipc_key()+2,1,IPC_CREAT|0600);
+  op.sem_num=0;
+  op.sem_op=1;
+  op.sem_flg=SEM_UNDO;
+  while (1) {
+    if (semop(sem_id,&op,1)) {
+      if (errno != EINTR) {
+        perror("semop(2): encountered an error");
+        exit(1);
+      }
+    } else {
+      break;
+    }
+  }
+}
+
 #else /* FAKEROOT_FAKENET */
+
 static struct sockaddr *get_addr(void)
 {
   static struct sockaddr_in addr = { 0, 0, { 0 } };
@@ -237,8 +260,6 @@ static struct sockaddr *get_addr(void)
       errno = 0;
       fail("FAKEROOTKEY not defined in environment");
     }
-#endif /* FAKEROOT_FAKENET */
-#ifdef FAKEROOT_FAKENET
 
     port = atoi(str);
     if (port <= 0 || port >= 65536) {
@@ -249,27 +270,10 @@ static struct sockaddr *get_addr(void)
     addr.sin_family = AF_INET;
     addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
     addr.sin_port = htons(port);
-#endif /* FAKEROOT_FAKENET */
   }
-#ifdef FAKEROOT_FAKENET
 
   return (struct sockaddr *) &addr;
-#endif /* FAKEROOT_FAKENET */
 }
-#ifndef FAKEROOT_FAKENET
-void semaphore_down(){
-  struct sembuf op;
-  if(sem_id==-1)
-    sem_id=semget(get_ipc_key()+2,1,IPC_CREAT|0600);
-  op.sem_num=0;
-  op.sem_op=1;
-  op.sem_flg=SEM_UNDO;
-  while (1) {
-    if (semop(sem_id,&op,1)) {
-      if (errno != EINTR) {
-	perror("semop(2): encountered an error");
-        exit(1);
-#else /* FAKEROOT_FAKENET */
 
 static void open_comm_sd(void)
 {
@@ -325,11 +329,7 @@ static void open_comm_sd(void)
 	if (errno == EINTR)
 	  continue;
 	fail("fcntl(F_DUPFD)");
-#endif /* FAKEROOT_FAKENET */
       }
-#ifndef FAKEROOT_FAKENET
-    } else {
-#else /* FAKEROOT_FAKENET */
     } while (0);
 
     close(comm_sd);
@@ -357,6 +357,81 @@ void close_comm_sd(void)
   pthread_mutex_unlock(&comm_sd_mutex);
 }
 
+#endif /* FAKEROOT_FAKENET */
+
+#ifndef FAKEROOT_FAKENET
+
+void send_fakem(const struct fake_msg *buf)
+{
+  int r;
+
+  if(init_get_msg()!=-1){
+    ((struct fake_msg *)buf)->mtype=1;
+    r=msgsnd(msg_snd, (struct fake_msg *)buf,
+	     sizeof(*buf)-sizeof(buf->mtype), 0);
+    if(r==-1)
+      perror("libfakeroot, when sending message");
+  }
+}
+
+void send_get_fakem(struct fake_msg *buf)
+{
+  /*
+  send and get a struct fakestat from the daemon.
+  We have to use serial/pid numbers in addidtion to
+     the semaphore locking, to prevent the following:
+
+  Client 1 locks and sends a stat() request to deamon.
+  meantime, client 2 tries to up the semaphore too, but blocks.
+  While client 1 is waiting, it recieves a KILL signal, and dies.
+  SysV semaphores can eighter be automatically cleaned up when
+  a client dies, or they can stay in place. We have to use the
+  cleanup version, as otherwise client 2 will block forever.
+  So, the semaphore is cleaned up when client 1 recieves the KILL signal.
+  Now, client 1 falls through the semaphore_up, and
+  sends a stat() request to the daemon --  it will now recieve
+  the answer intended for client 1, and hell breaks lose (yes,
+  this has actually happened, and yes, it was hell (to debug)).
+
+  I realise that I may well do away with the semaphore stuff,
+  if I put the serial/pid numbers in the mtype field. But I cannot
+  store both PID and serial in mtype (just 32 bits on Linux). So
+  there will always be some (small) chance it will go wrong.
+  */
+
+  int l;
+  pid_t pid;
+  static int serial=0;
+
+  if(init_get_msg()!=-1){
+    pid=getpid();
+    serial++;
+    buf->serial=serial;
+    semaphore_up();
+    buf->pid=pid;
+    send_fakem(buf);
+
+    do
+      l=msgrcv(msg_get,
+               (struct my_msgbuf*)buf,
+               sizeof(*buf)-sizeof(buf->mtype),0,0);
+    while((buf->serial!=serial)||buf->pid!=pid);
+
+    semaphore_down();
+
+    /*
+    (nah, may be wrong, due to allignment)
+
+    if(l!=sizeof(*buf)-sizeof(buf->mtype))
+    printf("libfakeroot/fakeroot, internal bug!! get_fake: length=%i != l=%i",
+    sizeof(*buf)-sizeof(buf->mtype),l);
+    */
+
+  }
+}
+
+#else /* FAKEROOT_FAKENET */
+
 static void send_fakem_nr(const struct fake_msg *buf)
 {
   struct fake_msg fm;
@@ -376,112 +451,35 @@ static void send_fakem_nr(const struct fake_msg *buf)
 
     len = write(comm_sd, &fm, sizeof (fm));
     if (len > 0)
-#endif /* FAKEROOT_FAKENET */
       break;
-#ifdef FAKEROOT_FAKENET
 
     if (len == 0) {
       errno = 0;
       fail("write: socket is closed");
-#endif /* FAKEROOT_FAKENET */
     }
-#ifdef FAKEROOT_FAKENET
 
     if (errno == EINTR)
       continue;
 
     fail("write");
-#endif /* FAKEROOT_FAKENET */
   }
 }
 
 void send_fakem(const struct fake_msg *buf)
 {
-#ifndef FAKEROOT_FAKENET
-  int r;
-  
-  if(init_get_msg()!=-1){
-    ((struct fake_msg *)buf)->mtype=1;
-    r=msgsnd(msg_snd, (struct fake_msg *)buf, 
-	     sizeof(*buf)-sizeof(buf->mtype), 0);
-    if(r==-1)
-      perror("libfakeroot, when sending message");         
-  }
-#else /* FAKEROOT_FAKENET */
   pthread_mutex_lock(&comm_sd_mutex);
 
   open_comm_sd();
   send_fakem_nr(buf);
 
   pthread_mutex_unlock(&comm_sd_mutex);
-#endif /* FAKEROOT_FAKENET */
 }
 
-#ifndef FAKEROOT_FAKENET
-void send_get_fakem(struct fake_msg *buf)
-{
-  /* 
-     send and get a struct fakestat from the daemon. 
-     We have to use serial/pid numbers in addidtion to 
-     the semaphore locking, to prevent the following:
-
-     Client 1 locks and sends a stat() request to deamon.
-     meantime, client 2 tries to up the semaphore too, but blocks.
-     While client 1 is waiting, it recieves a KILL signal, and dies.
-     SysV semaphores can eighter be automatically cleaned up when
-     a client dies, or they can stay in place. We have to use the
-     cleanup version, as otherwise client 2 will block forever.
-     So, the semaphore is cleaned up when client 1 recieves the KILL signal.
-     Now, client 1 falls through the semaphore_up, and
-     sends a stat() request to the daemon --  it will now recieve 
-     the answer intended for client 1, and hell breaks lose (yes,
-     this has actually happened, and yes, it was hell (to debug)).
-     
-     I realise that I may well do away with the semaphore stuff,
-     if I put the serial/pid numbers in the mtype field. But I cannot
-     store both PID and serial in mtype (just 32 bits on Linux). So 
-     there will always be some (small) chance it will go wrong.
-  */
-
-  int l;
-  pid_t pid;
-  static int serial=0;
-  
-#else /* FAKEROOT_FAKENET */
 static void get_fakem_nr(struct fake_msg *buf)
 {
   while (1) {
     ssize_t len;
-#endif /* FAKEROOT_FAKENET */
 
-#ifndef FAKEROOT_FAKENET
-  if(init_get_msg()!=-1){
-    pid=getpid();
-    serial++;
-    buf->serial=serial;
-    semaphore_up();
-    buf->pid=pid;
-    send_fakem(buf);
-    
-    do
-      l=msgrcv(msg_get,
-	       (struct my_msgbuf*)buf, 
-	       sizeof(*buf)-sizeof(buf->mtype),0,0);
-    while((buf->serial!=serial)||buf->pid!=pid);
-  
-    semaphore_down();
-  
-    /*
-      (nah, may be wrong, due to allignment)
-      
-      if(l!=sizeof(*buf)-sizeof(buf->mtype))
-      printf("libfakeroot/fakeroot, internal bug!! get_fake: length=%i != l=%i",
-      sizeof(*buf)-sizeof(buf->mtype),l);
-    */
- 
-  }
-  }
-#else /* FAKEROOT_FAKENET */
     len = read(comm_sd, buf, sizeof (struct fake_msg));
     if (len > 0)
       break;
@@ -515,42 +513,36 @@ void send_get_fakem(struct fake_msg *buf)
 
   pthread_mutex_unlock(&comm_sd_mutex);
 }
+
 #endif /* FAKEROOT_FAKENET */
+
 void send_stat(const struct stat *st,
 	       func_id_t f){
   struct fake_msg buf;
-#ifndef FAKEROOT_FAKENET
-  
-  if(init_get_msg()!=-1){
-#else /* FAKEROOT_FAKENET */
 
-#endif /* FAKEROOT_FAKENET */
+#ifndef FAKEROOT_FAKENET
+  if(init_get_msg()!=-1)
+#endif /* ! FAKEROOT_FAKENET */
+  {
     cpyfakemstat(&buf,st);
     buf.id=f;
     send_fakem(&buf);
-#ifndef FAKEROOT_FAKENET
   }
-#endif /* ! FAKEROOT_FAKENET */
 }
 
 #ifdef STAT64_SUPPORT
 void send_stat64(const struct stat64 *st,
-#ifndef FAKEROOT_FAKENET
-	       func_id_t f){
-#else /* FAKEROOT_FAKENET */
-		 func_id_t f){
-#endif /* FAKEROOT_FAKENET */
+                 func_id_t f){
   struct fake_msg buf;
-  
+
 #ifndef FAKEROOT_FAKENET
-  if(init_get_msg()!=-1){
+  if(init_get_msg()!=-1)
 #endif /* ! FAKEROOT_FAKENET */
+  {
     cpyfakemstat64(&buf,st);
     buf.id=f;
     send_fakem(&buf);
-#ifndef FAKEROOT_FAKENET
   }
-#endif /* ! FAKEROOT_FAKENET */
 }
 #endif /* STAT64_SUPPORT */
 
@@ -558,42 +550,35 @@ void send_get_stat(struct stat *st){
   struct fake_msg buf;
 
 #ifndef FAKEROOT_FAKENET
-  if(init_get_msg()!=-1){
+  if(init_get_msg()!=-1)
 #endif /* ! FAKEROOT_FAKENET */
+  {
     cpyfakemstat(&buf,st);
-#ifndef FAKEROOT_FAKENET
-    
-#else /* FAKEROOT_FAKENET */
 
-#endif /* FAKEROOT_FAKENET */
     buf.id=stat_func;
     send_get_fakem(&buf);
     cpystatfakem(st,&buf);
-#ifndef FAKEROOT_FAKENET
   }
-#endif /* ! FAKEROOT_FAKENET */
 }
 
 #ifdef STAT64_SUPPORT
-
 void send_get_stat64(struct stat64 *st)
 {
   struct fake_msg buf;
 
 #ifndef FAKEROOT_FAKENET
-  if(init_get_msg()!=-1){
+  if(init_get_msg()!=-1)
 #endif /* ! FAKEROOT_FAKENET */
+  {
     cpyfakemstat64(&buf,st);
-    
+
     buf.id=stat_func;
     send_get_fakem(&buf);
     cpystat64fakem(st,&buf);
-#ifndef FAKEROOT_FAKENET
   }
-#endif /* ! FAKEROOT_FAKENET */
 }
-
 #endif /* STAT64_SUPPORT */
+
 #ifndef FAKEROOT_FAKENET
 
 key_t get_ipc_key()
diff --git a/communicate.h b/communicate.h
index bd76e3a..44b4a78 100644
--- a/communicate.h
+++ b/communicate.h
@@ -27,22 +27,22 @@
 
 /* Then include features.h, to find out what glibc we run */
 #ifdef HAVE_FEATURES_H
-#include <features.h>
+# include <features.h>
 #endif
 
 #ifdef HAVE_SYS_FEATURE_TESTS_H
-#include <sys/feature_tests.h>
+# include <sys/feature_tests.h>
 #endif
 
 /* Then decide whether we do or do not use the stat64 support */
 #if defined(sun) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
-#define STAT64_SUPPORT
+# define STAT64_SUPPORT
 #else
-#warning Not using stat64 support
+# warning Not using stat64 support
 /* if glibc is 2.0 or older, undefine these again */
-#undef STAT64_SUPPORT
-#undef _LARGEFILE64_SOURCE 
-#undef _LARGEFILE_SOURCE 
+# undef STAT64_SUPPORT
+# undef _LARGEFILE64_SOURCE
+# undef _LARGEFILE_SOURCE
 #endif
 
 /* Sparc glibc 2.0.100 is broken, dlsym segfaults on --fxstat64.. 
@@ -52,14 +52,14 @@
 #include <sys/stat.h>
 #include <sys/utsname.h>
 #ifdef HAVE_STDINT_H
-#include <stdint.h>
+# include <stdint.h>
 #endif
 #ifdef HAVE_INTTYPES_H
-#include <inttypes.h>
+# include <inttypes.h>
 #endif
 
 #ifndef FAKEROOT_FAKENET
-#define FAKEROOTKEY_ENV "FAKEROOTKEY"
+# define FAKEROOTKEY_ENV          "FAKEROOTKEY"
 #endif /* ! FAKEROOT_FAKENET */
 
 #define FAKEROOTUID_ENV           "FAKEROOTUID"
@@ -75,24 +75,24 @@
 #define FAKELIBDIR                "/usr/lib/fakeroot"
 #define FAKELIBNAME               "libfakeroot.so.0"
 #ifdef FAKEROOT_FAKENET
-#define FD_BASE_ENV               "FAKEROOT_FD_BASE"
+# define FD_BASE_ENV              "FAKEROOT_FD_BASE"
 #endif /* FAKEROOT_FAKENET */
 #ifdef FAKEROOT_DB_PATH
-#define DB_SEARCH_PATHS_ENV       "FAKEROOT_DB_SEARCH_PATHS"
+# define DB_SEARCH_PATHS_ENV      "FAKEROOT_DB_SEARCH_PATHS"
 #endif /* FAKEROOT_DB_PATH */
 
 #ifdef __GNUC__
-#  define UNUSED __attribute__((unused))
-#else 
-#  define UNUSED 
+# define UNUSED __attribute__((unused))
+#else
+# define UNUSED
 #endif
 
 #ifndef S_ISTXT
-#  define S_ISTXT S_ISVTX
+# define S_ISTXT S_ISVTX
 #endif
 
 #ifndef ALLPERMS
-#  define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */
+# define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */
 #endif
 
 /* Define big enough _constant size_ types for the various types of the
@@ -117,41 +117,32 @@ enum {chown_func,
 
 #include "message.h"
 
+extern const char *env_var_set(const char *env);
+extern void send_stat(const struct stat *st, func_id_t f);
+extern void send_fakem(const struct fake_msg *buf);
+extern void send_get_stat(struct stat *buf);
+extern void cpyfakefake (struct fakestat *b1, const struct fakestat *b2);
+extern void cpystatfakem(struct     stat *st, const struct fake_msg *buf);
+
 #ifndef FAKEROOT_FAKENET
-  const char *env_var_set(const char *env);
-  extern int init_get_msg();
+extern int init_get_msg();
+extern key_t get_ipc_key();
+extern void cpyfakemstat(struct fake_msg *b1, const struct stat     *st);
 #else /* FAKEROOT_FAKENET */
-  extern const char *env_var_set(const char *env);
+extern void close_comm_sd(void);
 #endif /* FAKEROOT_FAKENET */
-  extern void send_stat(const struct stat *st, func_id_t f);
-  extern void send_fakem(const struct fake_msg *buf);
-  extern void send_get_stat(struct stat *buf);
-#ifndef FAKEROOT_FAKENET
-  extern void cpyfakemstat(struct fake_msg *b1, const struct stat     *st);
-  /*extern void cpyfakemfake(struct fake_msg *b1, const struct fakestat *b2);
-    extern void cpyfakefakem(struct fakestat *b1, const struct fake_msg *b2);
-  */
-  extern key_t get_ipc_key();
-#endif /* ! FAKEROOT_FAKENET */
-  extern void cpyfakefake (struct fakestat *b1, const struct fakestat *b2);
-  extern void cpystatfakem(struct    stat  *st,  const struct fake_msg *buf);
 
 #ifdef STAT64_SUPPORT  
-  extern void send_stat64(const struct stat64 *st, func_id_t f);
-  extern void send_get_stat64(struct stat64 *buf);
-  extern void stat64from32(struct stat64 *s64, const struct stat *s32);
-  extern void stat32from64(struct stat *s32, const struct stat64 *s64);
+extern void send_stat64(const struct stat64 *st, func_id_t f);
+extern void send_get_stat64(struct stat64 *buf);
+extern void stat64from32(struct stat64 *s64, const struct stat *s32);
+extern void stat32from64(struct stat *s32, const struct stat64 *s64);
 #endif
 
-#ifdef FAKEROOT_FAKENET
-  extern void close_comm_sd(void);
-
-#endif /* FAKEROOT_FAKENET */
-
 #ifndef FAKEROOT_FAKENET
 extern int msg_snd;
 extern int msg_get;
 extern int sem_id;
-
 #endif /* ! FAKEROOT_FAKENET */
+
 #endif
diff --git a/faked.c b/faked.c
index 6e74edd..ab4e3b8 100644
--- a/faked.c
+++ b/faked.c
@@ -14,7 +14,7 @@
   
   These tree running programs have the following tasks:
     
-    fakeroot scripot
+    fakeroot script
        starts the other two processes, waits for the user process to
        die, and then send a SIGTERM signal to faked, causing
        Faked to clear the ipc message queues.
@@ -63,7 +63,7 @@
     needs to keep a list of client pids vs cwd, and I'd have to wrap
     fork e.d., as they inherit their parent's cwd. Very compilcated.
     
-    */			       
+    */
 /* ipc documentation bugs: msgsnd(2): MSGMAX=4056, not 4080 
    (def in ./linux/msg.h, couldn't find other def in /usr/include/ 
    */
@@ -73,12 +73,17 @@
 #ifndef FAKEROOT_FAKENET
 # include <sys/ipc.h>
 # include <sys/msg.h>
+# include <sys/sem.h>
+#else /* FAKEROOT_FAKENET */
+# include <sys/socket.h>
+# include <sys/param.h>
+# include <netinet/in.h>
+# include <netinet/tcp.h>
+# include <arpa/inet.h>
+# include <netdb.h>
 #endif /* FAKEROOT_FAKENET */
 #include <sys/stat.h>
 #include <sys/wait.h>
-#ifndef FAKEROOT_FAKENET
-# include <sys/sem.h>
-#endif /* ! FAKEROOT_FAKENET */
 #include <sys/types.h>
 #include <fcntl.h>
 #include <ctype.h>
@@ -89,14 +94,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <signal.h>
-#ifdef FAKEROOT_FAKENET
-# include <sys/socket.h>
-# include <sys/param.h>
-# include <netinet/in.h>
-# include <netinet/tcp.h>
-# include <arpa/inet.h>
-# include <netdb.h>
-#endif /* FAKEROOT_FAKENET */
 #ifdef HAVE_STDINT_H
 # include <stdint.h>
 #endif
@@ -120,20 +117,21 @@
 #define fakestat_equal(a, b)  ((a)->dev == (b)->dev && (a)->ino == (b)->ino)
 
 #ifndef FAKEROOT_FAKENET
-#if HAVE_SEMUN_DEF == 0
+# if HAVE_SEMUN_DEF == 0
   union semun {
     int val;
     struct semid_ds *buf;
     u_short *array;
   };
-#endif
-
+# endif
 #endif /* ! FAKEROOT_FAKENET */
+
 void process_chown(struct fake_msg *buf);
 void process_chmod(struct fake_msg *buf);
 void process_mknod(struct fake_msg *buf);
 void process_stat(struct fake_msg *buf);
 void process_unlink(struct fake_msg *buf);
+
 #ifdef FAKEROOT_FAKENET
 static int get_fakem(struct fake_msg *buf);
 #endif
@@ -151,15 +149,14 @@ unsigned int highest_funcid = sizeof(func_arr)/sizeof(func_arr[0]);
 
 #ifndef FAKEROOT_FAKENET
 key_t msg_key=0;
+#else /* FAKEROOT_FAKENET */
+static int comm_sd = -1;
 #endif /* FAKEROOT_FAKENET */
+
 int debug = 0, unknown_is_real = 0;
 char *save_file = NULL;
 
 #ifdef FAKEROOT_FAKENET
-static int comm_sd = -1;
-#endif /* FAKEROOT_FAKENET */
-
-#ifdef FAKEROOT_FAKENET
 static void fail(const char *msg)
 {
   if (errno > 0)
@@ -735,19 +732,12 @@ void process_msg(struct fake_msg *buf){
 }
 
 #ifndef FAKEROOT_FAKENET
+
 void get_msg()
-#else /* FAKEROOT_FAKENET */
-void get_msg(const int listen_sd)
-#endif /* FAKEROOT_FAKENET */
 {
   struct fake_msg buf;
-#ifndef FAKEROOT_FAKENET
   int r = 0;
-#else /* FAKEROOT_FAKENET */
-  fd_set readfds;
-#endif /* FAKEROOT_FAKENET */
 
-#ifndef FAKEROOT_FAKENET
   if(debug)
     fprintf(stderr,"FAKEROOT: msg=%i, key=%i\n",msg_get,msg_key);
   do {
@@ -755,7 +745,22 @@ void get_msg(const int listen_sd)
     if(debug)
       fprintf(stderr,"FAKEROOT: r=%i, received message type=%li, message=%i\n",r,buf.mtype,buf.id);
     if(r!=-1)
+      buf.remote = 0;
+      process_msg(&buf);
+  }while ((r!=-1)||(errno==EINTR));
+  if(debug){
+    perror("FAKEROOT, get_msg");
+    fprintf(stderr,"r=%i, EINTR=%i\n",errno,EINTR);
+  }
+}
+
 #else /* FAKEROOT_FAKENET */
+
+void get_msg(const int listen_sd)
+{
+  struct fake_msg buf;
+  fd_set readfds;
+
   while (1) {
     int count, maxfd;
     unsigned int i;
@@ -815,7 +820,7 @@ void get_msg(const int listen_sd)
       if (debug) {
 	char host[256];
 	if (getnameinfo((struct sockaddr *) &addr, len, host, sizeof (host),
-			NULL, 0, 0) == 0)
+	    NULL, 0, 0) == 0)
 	  fprintf(stderr, "fakeroot: connection from %s, fd=%d\n", host, sd);
       }
 
@@ -829,23 +834,14 @@ void get_msg(const int listen_sd)
 	continue;
       }
 
-#endif /* FAKEROOT_FAKENET */
-#ifndef FAKEROOT_FAKENET
-      buf.remote = 0;
-      process_msg(&buf);
-  }while ((r!=-1)||(errno==EINTR));
-  if(debug){
-    perror("FAKEROOT, get_msg");
-    fprintf(stderr,"r=%i, EINTR=%i\n",errno,EINTR);
-#else /* FAKEROOT_FAKENET */
-
       process_msg(&buf);
       sd_list_add(sd);
-  }
-#endif /* FAKEROOT_FAKENET */
+    }
   }
 }
 
+#endif /* FAKEROOT_FAKENET */
+
 /***********/
 /*         */
 /* misc    */
@@ -861,24 +857,29 @@ void save(int dummy){
       fprintf(stderr, "fakeroot: database save FAILED\n");
 }
 
+#ifndef FAKEROOT_FAKENET
+# define FAKEROOT_CLEANUPMSG "fakeroot: clearing up message queues and semaphores, signal=%i\n"
+#else /* FAKEROOT_FAKENET */
+# define FAKEROOT_CLEANUPMSG "fakeroot: signal=%i\n"
+#endif /* FAKEROOT_FAKENET */
+
 void cleanup(int g)
 {
 #ifndef FAKEROOT_FAKENET
   union semun sem_union;
 #endif /* ! FAKEROOT_FAKENET */
+
   if(debug)
-#ifndef FAKEROOT_FAKENET
-# define FAKEROOT_CLEANUPMSG "fakeroot: clearing up message queues and semaphores, signal=%i\n"
-#else /* FAKEROOT_FAKENET */
-# define FAKEROOT_CLEANUPMSG "fakeroot: signal=%i\n"
-#endif /* FAKEROOT_FAKENET */
     fprintf(stderr, FAKEROOT_CLEANUPMSG,  g);
+
 #ifndef FAKEROOT_FAKENET
   msgctl (msg_get, IPC_RMID,NULL);
   msgctl (msg_snd, IPC_RMID,NULL);
   semctl (sem_id,0,IPC_RMID,sem_union);
 #endif /* ! FAKEROOT_FAKENET */
+
   save(0);
+
   if(g!=-1)
     exit(0);
 }
@@ -934,16 +935,15 @@ static int get_fakem(struct fake_msg *buf)
 #endif /* FAKEROOT_FAKENET */
 
 int main(int argc, char **argv){
-#ifndef FAKEROOT_FAKENET
-  union semun sem_union;
-  int justcleanup = 0;
-#endif /* FAKEROOT_FAKENET */
   struct sigaction sa,sa_debug,sa_save;
   int i;
   int foreground = 0;
   int load = 0;
   int pid;
-#ifdef FAKEROOT_FAKENET
+#ifndef FAKEROOT_FAKENET
+  union semun sem_union;
+  int justcleanup = 0;
+#else /* FAKEROOT_FAKENET */
   int sd, val;
   unsigned int port = 0;
   struct sockaddr_in addr;
@@ -955,6 +955,7 @@ int main(int argc, char **argv){
     fprintf(stderr,"Please, don't run fakeroot from within fakeroot!\n");
     exit(1);
   }
+
   while(*(++argv)){
     if(!strcmp(*argv,"--key"))
 #ifndef FAKEROOT_FAKENET
@@ -1000,13 +1001,17 @@ int main(int argc, char **argv){
       exit(1);
     }
   }
+
   init_hash_table();
+
   if(load)
     if(!load_database(0)) {
       fprintf(stderr,"Database load failed\n");
       exit(1);
     }
+
 #ifndef FAKEROOT_FAKENET
+
   if(!msg_key) {
     srandom(time(NULL)+getpid()*33151);
     while(!msg_key && (msg_key!=-1))  /* values 0 and -1 are treated
@@ -1029,6 +1034,13 @@ int main(int argc, char **argv){
     cleanup(-1);
     exit(1);
   }
+
+  if(debug)
+    fprintf(stderr,"msg_key=%i\n",msg_key);
+
+  if(justcleanup)
+    cleanup(0);
+
 #else /* FAKEROOT_FAKENET */
 
   sd = socket(PF_INET, SOCK_STREAM, 0);
@@ -1052,16 +1064,7 @@ int main(int argc, char **argv){
     if (bind(sd, (struct sockaddr *) &addr, sizeof (addr)) < 0)
       fail("bind");
   }
-#endif /* FAKEROOT_FAKENET */
-#ifndef FAKEROOT_FAKENET
-  if(debug)
-    fprintf(stderr,"msg_key=%i\n",msg_key);
-#endif /* ! FAKEROOT_FAKENET */
 
-#ifndef FAKEROOT_FAKENET
-  if(justcleanup)
-    cleanup(0);
-#else /* FAKEROOT_FAKENET */
   if (listen(sd, SOMAXCONN) < 0)
     fail("listen");
 
@@ -1070,6 +1073,7 @@ int main(int argc, char **argv){
     fail("getsockname");
 
   port = ntohs(addr.sin_port);
+
 #endif /* FAKEROOT_FAKENET */
 
   sa.sa_handler=cleanup;
@@ -1077,7 +1081,6 @@ int main(int argc, char **argv){
   sa.sa_flags=0;
   //  sa.sa_restorer=0;
 
-
   sa_debug.sa_handler=debugdata;
   sigemptyset(&sa_debug.sa_mask);
   sa_debug.sa_flags=0;
@@ -1131,6 +1134,7 @@ int main(int argc, char **argv){
     printf("%i:%i\n",FAKE_KEY,getpid());
     fflush(stdout);
   }
+
 #ifndef FAKEROOT_FAKENET
   get_msg();    /* we shouldn't return from this function */
 #else /* FAKEROOT_FAKENET */

-- 
fakeroot



More information about the Fakeroot-commits mailing list