chiark / gitweb /
*** empty log message ***
authorjames <james>
Sun, 2 Mar 2008 10:37:56 +0000 (10:37 +0000)
committerjames <james>
Sun, 2 Mar 2008 10:37:56 +0000 (10:37 +0000)
apps/sympathy.c
src/lockfile.c

index e1ed6e6832a70f595b3a25ea434aec26c9fd1100..0cbd75d1d23fa92e5f316cc9fa7969f7de5eade9 100644 (file)
@@ -11,6 +11,9 @@ static char rcsid[] =
 
 /*
  * $Log$
+ * Revision 1.29  2008/03/02 10:37:56  james
+ * *** empty log message ***
+ *
  * Revision 1.28  2008/03/02 10:27:24  james
  * *** empty log message ***
  *
@@ -150,11 +153,12 @@ fatal_moan (char *fmt, ...)
 
 
 char *
-teedious_snprint (char *fmt, va_alist * ap)
+teedious_snprintf (char *fmt, va_list  ap)
 {
-  va_alist *aq;
+  va_list aq;
   int size = 1024;
   char *buf = malloc (size);
+  int n;
 
   if (!buf)
     fatal_moan ("malloc failed");
@@ -207,8 +211,7 @@ gloo_paths (char *dir, char *leaf)
 char *
 mome (char *fmt, ...)
 {
-
-  char *rt, *home, *leaf;
+  char *ret, *home, *leaf;
   va_list ap;
 
 
@@ -232,7 +235,7 @@ mome (char *fmt, ...)
 }
 
 
-char *
+Socket *
 find_socket (char *fmt, ...)
 {
   Socket *ret;
@@ -295,8 +298,7 @@ list_sockets_in_dir (char *sockdir)
 
   int hostname_len = strlen (hostname);
 
-  if (!dir)
-    fatal_moan ("can't examine %s for sockets", sockdir);
+  if (!dir) return;
 
   rewinddir (dir);
 
@@ -337,15 +339,18 @@ list_sockets (void)
 
 
   for (ptr = socket_dirs; *ptr; ptr++) {
-    if (*ptr == '~') {
-      h = mome (ptr + 1);
+    if (**ptr == '~') {
+      h = mome (*ptr + 1);
     } else {
-      h = strdup (*ptr);
+      h = *ptr;
     }
 
     if (!h)
       continue;
+
     list_sockets_in_dir (h);
+
+    if (**ptr == '~') 
     free (h);
 
   }
index ce37079bf4eff7b3b54c540f50ccb6be4d49a00c..94cee444e8cc21ea483e156e177aa0f98667c997 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.10  2008/03/02 10:37:56  james
+ * *** empty log message ***
+ *
  * Revision 1.9  2008/02/15 23:52:12  james
  * *** empty log message ***
  *
@@ -122,11 +125,10 @@ void
 filelist_print (Filelist * fl, FILE * f)
 {
   Filelist_ent *fle;
-  if (!fl)
-    {
-      fprintf (f, "(empty list)\n");
-      return;
-    }
+  if (!fl) {
+    fprintf (f, "(empty list)\n");
+    return;
+  }
   for (fle = fl->head; fle; fle = fle->next)
     fprintf (f, "%s\n", fle->name);
 }
@@ -141,18 +143,14 @@ chown_uucp (fd)
   static int uuid = -1, ugid;
   struct passwd *pw;
 
-  if (uuid < 0)
-    {
-      if (pw = getpwnam ("uucp"))
-        {
-          uuid = pw->pw_uid;
-          ugid = pw->pw_gid;
-        }
-      else
-        {
-          return -1;
-        }
+  if (uuid < 0) {
+    if (pw = getpwnam ("uucp")) {
+      uuid = pw->pw_uid;
+      ugid = pw->pw_gid;
+    } else {
+      return -1;
     }
+  }
   return fchown (fd, uuid, ugid);
 }
 
@@ -179,28 +177,25 @@ lockfile_make (char *name)
 
   unlink (tmpfn);
   fd = open (tmpfn, O_WRONLY | O_CREAT | O_TRUNC, 0444);
-  if (fd < 0)
-    {
-      unlink (tmpfn);
-      return -1;
-    }
+  if (fd < 0) {
+    unlink (tmpfn);
+    return -1;
+  }
 
   write (fd, buf, i);
   fchmod (fd, 044);
-  if (chown_uucp (fd))
-    {
-      close (fd);
-      unlink (tmpfn);
-      return -1;
-    }
+  if (chown_uucp (fd)) {
+    close (fd);
+    unlink (tmpfn);
+    return -1;
+  }
 
   close (fd);
 
-  if (link (tmpfn, name) < 0)
-    {
-      unlink (tmpfn);
-      return -1;
-    }
+  if (link (tmpfn, name) < 0) {
+    unlink (tmpfn);
+    return -1;
+  }
 
   unlink (tmpfn);
   return 0;
@@ -219,29 +214,27 @@ lockfile_add_places (Filelist * fl, char *leaf)
   };
   int i;
 
-  for (i = 0; i < (sizeof (lock_dirs) / sizeof (char *)); ++i)
-    {
-      if (stat (lock_dirs[i], &stbuf))
-        continue;
-      strcpy (buf, lock_dirs[i]);
-      strcat (buf, "/");
-      strcat (buf, leaf);
-      filelist_add (fl, buf);
-    }
+  for (i = 0; i < (sizeof (lock_dirs) / sizeof (char *)); ++i) {
+    if (stat (lock_dirs[i], &stbuf))
+      continue;
+    strcpy (buf, lock_dirs[i]);
+    strcat (buf, "/");
+    strcat (buf, leaf);
+    filelist_add (fl, buf);
+  }
 }
 
 
 static void
 do_tedious_mangling (Filelist * fl, char *buf, char *ptr, char inv, int lower)
 {
-  while (*ptr)
-    {
-      if (lower && (*ptr >= 'A') && (*ptr <= 'Z'))
-        *ptr |= 32;
-      if (*ptr == '/')
-        *ptr = inv;
-      ptr++;
-    }
+  while (*ptr) {
+    if (lower && (*ptr >= 'A') && (*ptr <= 'Z'))
+      *ptr |= 32;
+    if (*ptr == '/')
+      *ptr = inv;
+    ptr++;
+  }
 
   lockfile_add_places (fl, buf);
 }
@@ -280,11 +273,10 @@ lockfile_add_name_from_path (Filelist * fl, char *file)
     ptr++;
   lockfile_regularize_and_add (fl, ptr);
 
-  if (!strncmp (ptr, "dev/", 4))
-    {
-      ptr += 4;
-      lockfile_regularize_and_add (fl, ptr);
-    }
+  if (!strncmp (ptr, "dev/", 4)) {
+    ptr += 4;
+    lockfile_regularize_and_add (fl, ptr);
+  }
 
 }
 
@@ -309,21 +301,20 @@ lockfile_check_dir_for_dev (Filelist * fl, char *dir, dev_t dev)
   if (!d)
     return;
 
-  while ((de = readdir (d)))
-    {
-      strcpy (buf, dir);
-      strcat (buf, de->d_name);
+  while ((de = readdir (d))) {
+    strcpy (buf, dir);
+    strcat (buf, de->d_name);
 
-      if (stat (buf, &ent_stat))
-        continue;
-      if (!S_ISCHR (ent_stat.st_mode))
-        continue;
-      if (ent_stat.st_rdev != dev)
-        continue;
+    if (stat (buf, &ent_stat))
+      continue;
+    if (!S_ISCHR (ent_stat.st_mode))
+      continue;
+    if (ent_stat.st_rdev != dev)
+      continue;
 
-      lockfile_add_name_from_path (fl, buf);
+    lockfile_add_name_from_path (fl, buf);
 
-    }
+  }
   closedir (d);
 }
 
@@ -370,31 +361,28 @@ remove_stale_lock (char *path)
   apid[length] = 0;
 
   pid = 0;
-  if (length == sizeof (pid) || sscanf (apid, "%d", &pid) != 1 || pid == 0)
-    {
-      pid = *((int *) apid);
+  if (length == sizeof (pid) || sscanf (apid, "%d", &pid) != 1 || pid == 0) {
+    pid = *((int *) apid);
 #ifdef LOCK_ASCII
-      fprintf (stderr,
-               "compiled with ascii locks, found binary lock file (length=%d, pid=%d)!",
-               length, pid);
+    fprintf (stderr,
+             "compiled with ascii locks, found binary lock file (length=%d, pid=%d)!",
+             length, pid);
 #endif
-    }
+  }
 #ifdef LOCK_BINARY
-  else
-    {
-      fprintf (stderr,
-               "compiled with binary locks, found ascii lock file (length=%d, pid=%d)!",
-               length, pid);
-    }
+  else {
+    fprintf (stderr,
+             "compiled with binary locks, found ascii lock file (length=%d, pid=%d)!",
+             length, pid);
+  }
 #endif
 
   close (fd);
 
-  if ((kill (pid, 0) < 0) && (errno == ESRCH))
-    {
-      fprintf (stderr, "removing stale lock file %s\n", path);
-      unlink (path);
-    }
+  if ((kill (pid, 0) < 0) && (errno == ESRCH)) {
+    fprintf (stderr, "removing stale lock file %s\n", path);
+    unlink (path);
+  }
 
 }
 
@@ -404,12 +392,11 @@ lockfile_remove_stale (Filelist * fl)
   Filelist_ent *fle;
   struct stat buf;
 
-  for (fle = fl->head; fle; fle = fle->next)
-    {
-      if (stat (fle->name, &buf))
-        continue;
-      remove_stale_lock (fle->name);
-    }
+  for (fle = fl->head; fle; fle = fle->next) {
+    if (stat (fle->name, &buf))
+      continue;
+    remove_stale_lock (fle->name);
+  }
 
 
 }
@@ -425,16 +412,14 @@ lockfile_lock (Filelist * fl)
 
   lockfile_remove_stale (fl);
 
-  for (fle = fl->head; fle; fle = fle->next)
-    {
-      if (lockfile_make (fle->name))
-        {
-          fprintf (stderr, "Failed to get lockfile %s\n", fle->name);
-          filelist_free (ret);
-          return NULL;
-        }
-      filelist_add (ret, fle->name);
+  for (fle = fl->head; fle; fle = fle->next) {
+    if (lockfile_make (fle->name)) {
+      fprintf (stderr, "Failed to get lockfile %s\n", fle->name);
+      filelist_free (ret);
+      return NULL;
     }
+    filelist_add (ret, fle->name);
+  }
 
   return ret;
 }
@@ -443,11 +428,10 @@ void
 lockfile_unlock (Filelist * fl)
 {
 
-  while (fl->head)
-    {
-      unlink (fl->head->name);
-      filelist_remove (fl, fl->head);
-    }
+  while (fl->head) {
+    unlink (fl->head->name);
+    filelist_remove (fl, fl->head);
+  }
 }
 
 
@@ -464,11 +448,10 @@ serial_lock_check (Serial_lock * l)
   if (l->mode == SERIAL_LOCK_ACTIVE)
     return 0;
 
-  for (fle = l->locks_to_check->head; fle; fle = fle->next)
-    {
-      if (!stat (fle->name, &buf))
-        locks_found++;
-    }
+  for (fle = l->locks_to_check->head; fle; fle = fle->next) {
+    if (!stat (fle->name, &buf))
+      locks_found++;
+  }
 
   if (!locks_found)
     return 0;
@@ -476,11 +459,10 @@ serial_lock_check (Serial_lock * l)
   gettimeofday (&now, NULL);
   timersub (&now, &l->last_stale_purge, &dif);
 
-  if (dif.tv_sec > STALE_CHECK_INTERVAL)
-    {
-      lockfile_remove_stale (l->locks_to_check);
-      l->last_stale_purge = now;
-    }
+  if (dif.tv_sec > STALE_CHECK_INTERVAL) {
+    lockfile_remove_stale (l->locks_to_check);
+    l->last_stale_purge = now;
+  }
 
   return 1;
 }
@@ -491,16 +473,14 @@ serial_lock_free (Serial_lock * l)
   if (!l)
     return;
 
-  if (l->locks_held)
-    {
-      lockfile_unlock (l->locks_held);
-      filelist_free (l->locks_held);
-    }
+  if (l->locks_held) {
+    lockfile_unlock (l->locks_held);
+    filelist_free (l->locks_held);
+  }
 
-  if (l->locks_to_check)
-    {
-      filelist_free (l->locks_to_check);
-    }
+  if (l->locks_to_check) {
+    filelist_free (l->locks_to_check);
+  }
 
   free (l);
 }
@@ -526,11 +506,10 @@ serial_lock_new (char *dev, int mode)
     return l;
 
   l->locks_held = lockfile_lock (l->locks_to_check);
-  if (!l->locks_held)
-    {
-      serial_lock_free (l);
-      return NULL;
-    }
+  if (!l->locks_held) {
+    serial_lock_free (l);
+    return NULL;
+  }
 
   return l;
 }