changeset:   2:bd7cfb8e4d21
tag:         tip
user:        Dimitrios Papastamos <stateless [at] archlinux.us>
date:        Wed Apr 29 01:46:42 2009 -0700
files:       HACKING Makefile TODO skvm.1 skvm.c
description:
General code cleanup. Fixed inconsistent return values. Added HACKING
and altered the manpage. Code re-organization.
diff -r 22990e73c952 -r bd7cfb8e4d21 HACKING
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HACKING	Wed Apr 29 01:46:42 2009 -0700
@@ -0,0 +1,8 @@
+Coding style and project aims
+=============================
+
+If you plan to hack this code, please follow the coding convetions
+used in the current code. Use format.sh and the latest version of astyle
+to format the code. This project does not aim to be portable as it is
+mainly used on Linux. Make sure the code is secure as skvm is meant
+to execute as root.
diff -r 22990e73c952 -r bd7cfb8e4d21 Makefile
--- a/Makefile	Tue Apr 28 20:49:09 2009 -0700
+++ b/Makefile	Wed Apr 29 01:46:42 2009 -0700
@@ -20,7 +20,7 @@
 dist: clean
         @mkdir -p skvm-${ver}
         @cp -R AUTHORS ChangeLog PKGBUILD README skvm.1 ${src} \
-		LICENSE Makefile TODO init skvm-${ver}
+		LICENSE HACKING format.sh .astylerc Makefile TODO init skvm-${ver}
         @tar -cf skvm-${ver}.tar skvm-${ver}
         @bzip2 skvm-${ver}.tar
         @rm -rf skvm-${ver}
diff -r 22990e73c952 -r bd7cfb8e4d21 TODO
--- a/TODO	Tue Apr 28 20:49:09 2009 -0700
+++ b/TODO	Wed Apr 29 01:46:42 2009 -0700
@@ -1,4 +1,3 @@
 SKVM --- TODO
 
         * add support for LUKS.
-	* better error reporting.
diff -r 22990e73c952 -r bd7cfb8e4d21 skvm.1
--- a/skvm.1	Tue Apr 28 20:49:09 2009 -0700
+++ b/skvm.1	Wed Apr 29 01:46:42 2009 -0700
@@ -17,3 +17,6 @@
 file and (re)compiling the source code. This keeps it fast, secure and simple.
 .SH AUTHOR
 skvm was written by Dimitrios Papastamos <stateless [at] archlinux.us>.
+.SH PATCHES
+you can submit your own patches to skvm by subscribing to <hackers [at] suckless.org>
+as outlined at suckless.org.
diff -r 22990e73c952 -r bd7cfb8e4d21 skvm.c
--- a/skvm.c	Tue Apr 28 20:49:09 2009 -0700
+++ b/skvm.c	Wed Apr 29 01:46:42 2009 -0700
@@ -1,7 +1,6 @@
 /* See LICENSE file for copyright and license details. */
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdarg.h>
 #include <string.h>
 #include <errno.h>
 #include <signal.h>
@@ -93,14 +92,17 @@
  * ============================
  */
 
+/* (de)/initialization functions */
 static int init_skvm(void);
 static int init_dbus(DBusError *error);
 static int init_hal(void);
+static void deinit(void);
 
-static void register_hal_callbacks(void);
+/* callback functions */
 static void device_added(LibHalContext *context, const char *did);
 static void device_removed(LibHalContext *context, const char *did);
 
+/* functions related to the device list */
 static struct device_t *get_device(char *mountp, const char *did,
                                    char *dev, char *label,
                                    const char *fstype,
@@ -111,16 +113,19 @@
                                     struct device_t *curr);
 static void free_device(struct device_t *device);
 
+/* functions related to how the volume manager behaves when
+ * a new device is inserted */
 static int is_mounted(const char *dev);
 static char *get_mount_point(const char *dev, const char *label);
 static int resolve_symlink(const char *f, char *d, size_t d_len);
 static void consider_fstab(struct device_t *device);
 static void do_args(struct device_t *device);
 static int do_mount(struct device_t *device);
+
+/* general function helpers */
 static int file_exists(const char *path);
 static void cleanup(int sig);
 static int is_running(void);
-static void deinit(void);
 static void debug_dump_device(const struct device_t *device);
 
 int
@@ -141,7 +146,7 @@
    }
 
    if (debug_mode_flag)
-      setvbuf(stdout, (char *)NULL, _IONBF, 0);
+      setvbuf(stdout, (char *)NULL, _IONBF, 0); /* avoid surprises */
 
    if (init_skvm() < 0)
       return EXIT_FAILURE;
@@ -156,11 +161,6 @@
          deinit();
          return EXIT_FAILURE;
       }
-   }
-
-   if (debug_mode_flag) {
-      printf("Base mount directory: %s\n", BASE_MNT_DIR);
-      printf("Default mount options: %s\n", DEFAULT_MNT_OPTIONS);
    }
 
    loop = g_main_loop_new((GMainContext *)NULL, FALSE);
@@ -204,7 +204,9 @@
       return -1;
 
    libhal_ctx_set_dbus_connection (hal_ctx, dbus_conn);
-   register_hal_callbacks();
+
+   libhal_ctx_set_device_added(hal_ctx, device_added);
+   libhal_ctx_set_device_removed(hal_ctx, device_removed);
 
    dbus_error_init(&error);
    if (!libhal_device_property_watch_all(hal_ctx, &error)) {
@@ -231,12 +233,27 @@
 }
 
 static void
-register_hal_callbacks(void) {
-   libhal_ctx_set_device_added(hal_ctx, device_added);
-   libhal_ctx_set_device_removed(hal_ctx, device_removed);
+deinit(void) {
+   struct device_t *iter, *tmp;
+
+   closelog();
+   libhal_ctx_shutdown(hal_ctx, (DBusError *)NULL);
+   libhal_ctx_free(hal_ctx);
+   dbus_connection_unref(dbus_conn);
+
+   iter = head;
+
+   while (iter) {
+      tmp = iter;
+      iter = iter->next;
+      free_device(tmp);
+   }
+
+   if (pid_fd >= 0)
+      close(pid_fd); /* releases lock */
 }
 
-/* Callback function, called when a new device has been inserted */
+/* Callback function, called when a new device has been inserted. */
 static void
 device_added(LibHalContext *context, const char *did) {
    const char *dudi, *fstype;
@@ -289,7 +306,7 @@
       libhal_free_string(label);
 }
 
-/* Callback function, called when a device has been removed */
+/* Callback function, called when a device has been removed. */
 static void
 device_removed(LibHalContext *context __attribute__ ((unused)),
                const char *did) {
@@ -582,7 +599,7 @@
 }
 
 /*
- * Check if skvm is already running, make sure the log
+ * Check if skvm is already running, the caller has to make sure that the log
  * file has been opened and the new instance has been daemonized.
  */
 static int
@@ -593,7 +610,7 @@
    if (pid_fd < 0) {
       syslog(LOG_ERR, "%s:%d %s", __FILE__, __LINE__,
              strerror(errno));
-      return 1;
+      return -1;
    }
 
    if (flock(pid_fd, LOCK_EX | LOCK_NB) < 0) {
@@ -601,34 +618,13 @@
       pid_fd = -1;
       syslog(LOG_ERR, "%s:%d can't lock %s: %s", __FILE__, __LINE__,
              LOCKFILE, strerror(errno));
-      return 1;
+      return -1;
    }
 
    ftruncate(pid_fd, 0);
    snprintf(buf, sizeof(buf), "%jd\n", (intmax_t)getpid());
    write(pid_fd, buf, strlen(buf));
    return 0;
-}
-
-static void
-deinit(void) {
-   struct device_t *iter, *tmp;
-
-   closelog();
-   libhal_ctx_shutdown(hal_ctx, (DBusError *)NULL);
-   libhal_ctx_free(hal_ctx);
-   dbus_connection_unref(dbus_conn);
-
-   iter = head;
-
-   while (iter) {
-      tmp = iter;
-      iter = iter->next;
-      free_device(tmp);
-   }
-
-   if (pid_fd != -1)
-      close(pid_fd); /* releases lock */
 }
 
 static void
Received on Wed Apr 29 2009 - 00:47:20 UTC
This archive was generated by hypermail 2.2.0 : Wed Apr 29 2009 - 00:48:04 UTC