]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge commit 'remotes/meins/v0.3' into v0.3
authorAndre Noll <maan@systemlinux.org>
Fri, 21 Sep 2007 09:01:13 +0000 (11:01 +0200)
committerAndre Noll <maan@systemlinux.org>
Fri, 21 Sep 2007 09:01:13 +0000 (11:01 +0200)
38 files changed:
Makefile.in
afs_common.c
alsa_write.c
audioc.c
audiod.c
audiod_command.c
client_common.c
command.c
configure.ac
dccp.c
dccp_recv.c
dccp_send.c
error.h
fade.c
fd.c
fd.h
file_write.c
filter_chain.c
fsck.c
fsck.ggo [new file with mode: 0644]
grab_client.c
gui.c
gui_common.c
http_recv.c
http_send.c
osl.c
osl.h
recv.c
sched.c
sdl_gui.c
server.c
signal.c
stat.c
stdin.c
stdout.c
user_list.c
vss.c
write.c

index 0cce0a7739e37a9709d7190ee84019b33a77307b..cd2f9c3ec52c98ee3ac0c840d4a112e56a430f94 100644 (file)
@@ -97,7 +97,7 @@ dbadm_objs = dbadm.o exec.o close_on_fork.o string.o
 fade_objs = fade.cmdline.o fade.o exec.o close_on_fork.o string.o fd.o
 krell_objs = krell.o string.o
 slider_objs = slider.o string.o
-fsck_objs = osl.o rbtree.o fsck.o string.o sha1.o
+fsck_objs = osl.o rbtree.o fsck.o string.o sha1.o fsck.cmdline.o
 
 *.o: para.h config.h gcc-compat.h
 
@@ -139,10 +139,11 @@ grab_client.cmdline.h grab_client.cmdline.c: grab_client.ggo
 %.cmdline.h %.cmdline.c: %.ggo
        case $< in client.ggo) O="--unamed-opts=command";; \
                audioc.ggo) O="--unamed-opts=command";; \
+               fsck.ggo) O="--unamed-opts=table";; \
        esac; \
+       echo "$O"; if test $< != fsck.ggo; then O="$$O --conf-parser "; fi; \
        gengetopt $$O \
                --no-handle-version \
-               --conf-parser \
                --file-name=$(*F).cmdline \
                --func-name $(*F)_cmdline_parser \
                --arg-struct-name=$(*F)_args_info \
@@ -245,8 +246,8 @@ para_fade: $(fade_objs)
 para_server: @server_objs@
        $(CC) -o $@ @server_objs@  @server_ldflags@
 
-para_fsck: $(fsck_objs)
-       $(CC) -o $@ $(fsck_objs) -lssl
+para_fsck: @fsck_objs@
+       $(CC) -o $@ @fsck_objs@ @fsck_ldflags@
 
 para_sdl_gui: $(sdl_gui_objs)
        $(CC) -o $@ $(sdl_gui_objs) -lSDL_image
index 72be6a9da47223b2849b28c97c1427a7cb22df59..17b4e16ff8f43c0b075d0f949bb3a0c7f35a1809 100644 (file)
@@ -7,7 +7,12 @@
 
 /** \file afs_common.c Functions common to all audio file selectors. */
 
+#include <sys/types.h>
+#include <dirent.h>
+
+
 #include "para.h"
+#include "fd.h"
 #include "server.cmdline.h"
 #include "afh.h"
 #include "server.h"
 int find_audio_files(const char *dirname, int (*f)(const char *, const char *))
 {
        DIR *dir = NULL;
+       int ret, ret2, cwd_fd;
        struct dirent *entry;
-       /*
-        * Opening the current directory (".") and calling fchdir() to return
-        * is usually faster and more reliable than saving cwd in some buffer
-        * and calling chdir() afterwards (see man 3 getcwd).
-        */
-       int cwd_fd = open(".", O_RDONLY);
-       struct stat s;
-       int ret;
 
-       if (cwd_fd < 0)
-               return -E_GETCWD;
-       ret = -E_CHDIR;
-       if (chdir(dirname) < 0)
-               goto out;
-       ret = -E_OPENDIR;
-       dir = opendir(".");
-       if (!dir)
-               goto out;
+       ret = para_opendir(dirname, &dir, &cwd_fd);
+       if (ret < 0)
+               return ret;
        /* scan cwd recursively */
        while ((entry = readdir(dir))) {
                mode_t m;
                char *tmp;
+               struct stat s;
 
                if (!strcmp(entry->d_name, "."))
                        continue;
@@ -87,8 +80,9 @@ int find_audio_files(const char *dirname, int (*f)(const char *, const char *))
 out:
        if (dir)
                closedir(dir);
-       if (fchdir(cwd_fd) < 0)
-               ret = -E_CHDIR;
+       ret2 = fchdir(cwd_fd);
+       if (ret2 < 0 && ret >= 0)
+               ret = ret2;
        close(cwd_fd);
        if (ret < 0)
                PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
index 6f92612a2221c5bf132b786f9fd67a9872c777cd..3ad8f5dfe84c5e93dfdd9e2d8d81e3fa7f7c7d22 100644 (file)
  * based on the vplay program by Michael Beck.
  */
 
+#include <sys/types.h>
+#include <dirent.h>
+#include <alsa/asoundlib.h>
+
 #include "para.h"
 #include "fd.h"
 #include "string.h"
 #include "list.h"
 #include "sched.h"
 #include "write.h"
-
-#include <alsa/asoundlib.h>
-
 #include "alsa_write.cmdline.h"
 #include "error.h"
 
index 15faebf1d49283123370a15521ee26e5dddc6ade..66ff2a267dc5228056cce913055afc177f9c6560 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -6,6 +6,9 @@
 
 /** \file audioc.c the client program used to connect to para_audiod */
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "audioc.cmdline.h"
 #include "para.h"
 #include "error.h"
index 5e0ff8d49f2dec598f1b87c64b1bf421dd9266a6..1fdbea7563803b3648d18eba95441e3ebb99b18e 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -5,6 +5,8 @@
  */
 
 /** \file audiod.c the paraslash's audio daemon */
+#include <sys/types.h>
+#include <dirent.h>
 
 #include "para.h"
 #include "error.h"
index ea8c1a582f3301e08ca34798935adce5f5357228..d424cf2e76f32ca90058685b68186b5a00be6a2b 100644 (file)
@@ -6,8 +6,10 @@
 
 /** \file audiod_command.c commands for para_audiod */
 
-#include "para.h"
+#include <sys/types.h>
+#include <dirent.h>
 
+#include "para.h"
 #include "audiod.cmdline.h"
 #include "list.h"
 #include "close_on_fork.h"
index d950d2d744801c721b132cc13b45b10422faf289..7c93b91722649a2a5386db892d444702025b07bd 100644 (file)
@@ -6,6 +6,9 @@
 
 /** \file client_common.c common functions of para_client and para_audiod */
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "para.h"
 #include "error.h"
 #include "list.h"
index 212a1800e1a32726096c3461c05ee2e9a3bacbfb..072b972cb5754122aa539178edbf6cf43a19d3e3 100644 (file)
--- a/command.c
+++ b/command.c
@@ -6,9 +6,12 @@
 
 /** \file command.c does client authentication and executes server commands */
 
-#include <sys/time.h> /* gettimeofday */
-#include "para.h" /* gettimeofday */
+#include <sys/time.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <openssl/rc4.h>
 
+#include "para.h"
 #include "server.cmdline.h"
 #include "afs_common.h"
 #include "afh.h"
@@ -16,7 +19,6 @@
 #include "vss.h"
 #include "send.h"
 #include "rc4.h"
-#include <openssl/rc4.h>
 #include "error.h"
 #include "net.h"
 #include "daemon.h"
index 1c9bee43d757fc5152c7bdbc587a63ee86ff86a8..1c7925dbb0897d093f81ec8f294598fa59c9b939 100644 (file)
@@ -124,6 +124,10 @@ client_cmdline_objs="client.cmdline"
 client_errlist_objs="client net string crypt fd sched stdin stdout client_common"
 client_ldflags=""
 
+fsck_cmdline_objs="fsck.cmdline"
+fsck_errlist_objs="osl rbtree fsck string sha1 fd"
+
+
 ########################################################################### ssl
 dnl @synopsis CHECK_SSL
 dnl
@@ -173,6 +177,7 @@ CHECK_SSL($enable_ssldir)
 server_ldflags="$srver_ldflags $SSL_LDFLAGS $SSL_LIBS"
 client_ldflags="$client_ldflags $SSL_LDFLAGS $SSL_LIBS"
 audiod_ldflags="$audiod_ldflags $SSL_LDFLAGS $SSL_LIBS"
+fsck_ldflags="$fsck_ldflags $SSL_LDFLAGS $SSL_LIBS"
 
 ########################################################################### ucred
 AC_MSG_CHECKING(for struct ucred)
@@ -524,6 +529,7 @@ audiod_objs="$audiod_cmdline_objs $audiod_errlist_objs"
 server_objs="$server_cmdline_objs $server_errlist_objs"
 write_objs="$write_cmdline_objs $write_errlist_objs"
 client_objs="$client_cmdline_objs $client_errlist_objs"
+fsck_objs="$fsck_cmdline_objs $fsck_errlist_objs"
 audioc_objs="$audioc_cmdline_objs $audioc_errlist_objs"
 
 AC_SUBST(recv_objs, add_dot_o($recv_objs))
@@ -556,6 +562,11 @@ AC_SUBST(client_ldflags, $client_ldflags)
 AC_DEFINE_UNQUOTED(INIT_CLIENT_ERRLISTS,
        objlist_to_errlist($client_errlist_objs), errors used by para_client)
 
+AC_SUBST(fsck_objs, add_dot_o($fsck_objs))
+AC_SUBST(fsck_ldflags, $fsck_ldflags)
+AC_DEFINE_UNQUOTED(INIT_FSCK_ERRLISTS,
+       objlist_to_errlist($fsck_errlist_objs), errors used by para_fsck)
+
 AC_SUBST(audioc_objs, add_dot_o($audioc_objs))
 AC_DEFINE_UNQUOTED(INIT_AUDIOC_ERRLISTS,
        objlist_to_errlist($audioc_errlist_objs), errors used by para_audioc)
diff --git a/dccp.c b/dccp.c
index 62de4f7d6492fee1c616825b554c5276a93f2e0f..52782732c3164075cc1fd130f01e4b26932dc517 100644 (file)
--- a/dccp.c
+++ b/dccp.c
@@ -11,6 +11,9 @@
  * (C) 2005 Ian McDonald <imcdnzl@gmail.com>
  */
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "para.h"
 #include "error.h"
 #include "dccp.h"
index 2f946fc61726e07a36853ee4ad2c2784776964f9..47351afbae731a08498f08692074b1670a05c490 100644 (file)
@@ -11,6 +11,9 @@
  * (C) 2005 Ian McDonald <imcdnzl@gmail.com>
  */
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "para.h"
 #include "error.h"
 #include "dccp.h"
index 3509d5d88a5e18f00089885ae7be41b8207e1b17..c506fd96f15c222386fc14b5c7a0d74462e31f4e 100644 (file)
@@ -11,6 +11,9 @@
  * (C) 2005 Ian McDonald <imcdnzl@gmail.com>
  */
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "para.h"
 #include "error.h"
 #include "afh.h"
diff --git a/error.h b/error.h
index 98b702c4f3c89aa5c383e5b0a29d2ee487d6ddbd..7d2424cf3a626e27be056af432300be0911b76b9 100644 (file)
--- a/error.h
+++ b/error.h
@@ -74,6 +74,7 @@ enum para_subsystem {
        SS_PLAYLIST,
        SS_SHA1,
        SS_RBTREE,
+       SS_FSCK,
        NUM_SS
 };
 
@@ -94,9 +95,13 @@ enum para_subsystem {
 extern const char **para_errlist[];
 /** \endcond */
 
+#define FSCK_ERRORS \
+       PARA_ERROR(FSCK_SYNTAX, "fsck syntax error"), \
+       PARA_ERROR(RANGE_VIOLATION, "range violation detected, very bad"), \
+       PARA_ERROR(NOT_A_REGULAR_FILE, "not a regular file"), \
+
+
 #define OSL_ERRORS \
-       PARA_ERROR(OSL_OPENDIR, "can not open directory"), \
-       PARA_ERROR(OSL_CHDIR, "failed to change directory"), \
        PARA_ERROR(BAD_DB_DIR, "invalid database directory"), \
        PARA_ERROR(NO_COLUMN_DESC, "missing column description"), \
        PARA_ERROR(BAD_NAME, "invalid name for a column/table"), \
@@ -116,26 +121,18 @@ extern const char **para_errlist[];
        PARA_ERROR(BAD_SIZE, "invalid size specified"), \
        PARA_ERROR(TRUNC, "failed to truncate file"), \
        PARA_ERROR(UNLINK, "failed to remove file"), \
-       PARA_ERROR(EXIST, "file or directory already exists"), \
-       PARA_ERROR(ISDIR, "error: is a directory"), \
        PARA_ERROR(NOTDIR, "error: not a directory"), \
-       PARA_ERROR(NOENT, "no such file or directory"), \
-       PARA_ERROR(OSL_PERM, "permission denied"), \
        PARA_ERROR(BAD_TABLE, "table not open"), \
-       PARA_ERROR(BAD_TABLE_HEADER, "table header corruption"), \
        PARA_ERROR(BAD_TABLE_DESC, "invalid table description"), \
        PARA_ERROR(RB_KEY_EXISTS, "key already exists in rbtree"), \
        PARA_ERROR(RB_KEY_NOT_FOUND, "key not found in rbtree"), \
        PARA_ERROR(BAD_ROW_NUM, "invalid row number"), \
        PARA_ERROR(INDEX_CORRUPTION, "index corruption detected"), \
        PARA_ERROR(INVALID_OBJECT, "reference to invalid object"), \
-       PARA_ERROR(MKDIR, "failed to create directory"), \
-       PARA_ERROR(OPEN, "failed to open file"), \
        PARA_ERROR(STAT, "can not stat file"), \
        PARA_ERROR(FSTAT, "fstat error"), \
        PARA_ERROR(RENAME, "rename failed"), \
        PARA_ERROR(EMPTY, "file empty"), \
-       PARA_ERROR(NOSPC, "no space left on device"), \
        PARA_ERROR(MMAP, "mmap error"), \
        PARA_ERROR(MUNMAP, "munmap failed"), \
        PARA_ERROR(WRITE, "write error"), \
@@ -146,20 +143,17 @@ extern const char **para_errlist[];
        PARA_ERROR(VERSION_MISMATCH, "table version not suppoerted"), \
        PARA_ERROR(BAD_COLUMN_NUM, "invalid column number"), \
        PARA_ERROR(BAD_TABLE_FLAGS, "invalid flags in table description"), \
-       PARA_ERROR(RBTREE_EMPTY, "rbtree is empty"), \
        PARA_ERROR(BAD_ROW, "invalid row"), \
-       PARA_ERROR(OSL_GETCWD, "can not get current working directory"), \
-       PARA_ERROR(OSL_LSTAT, "lstat error"), \
 
 
 #define RBTREE_ERRORS \
 
 
 #define AFS_ERRORS \
-       PARA_ERROR(AFS_SYNTAX, "afs syntax error"), \
-       PARA_ERROR(FORK, "fork error"), \
        PARA_ERROR(BAD_TABLE_NAME, "invalid table"), \
        PARA_ERROR(INPUT_TOO_LARGE, "input too large for stdin command"), \
+       PARA_ERROR(READ, "read error"), \
+       PARA_ERROR(ATOL, "failed to convert to long"), \
 
 
 #define MOOD_ERRORS \
@@ -169,8 +163,6 @@ extern const char **para_errlist[];
        PARA_ERROR(MOOD_LOADED, "mood loaded"), \
        PARA_ERROR(MOOD_BUSY, "mood is in use"), \
        PARA_ERROR(NOT_ADMISSIBLE, "file is not admussible"), \
-       PARA_ERROR(READ, "read error"), \
-       PARA_ERROR(ATOL, "failed to convert to long"), \
 
 
 #define ATTRIBUTE_ERRORS \
@@ -401,8 +393,6 @@ extern const char **para_errlist[];
 
 #define AFS_COMMON_ERRORS \
        PARA_ERROR(GETCWD, "can not get current working directory"), \
-       PARA_ERROR(CHDIR, "can not change directory"), \
-       PARA_ERROR(OPENDIR, "can not open directory"), \
        PARA_ERROR(LSTAT, "lstat error"), \
 
 
@@ -494,6 +484,17 @@ extern const char **para_errlist[];
        PARA_ERROR(F_GETFL, "failed to get fd flags"), \
        PARA_ERROR(F_SETFL, "failed to set fd flags"), \
        PARA_ERROR(FGETS, "fgets error"), \
+       PARA_ERROR(EXIST, "file or directory already exists"), \
+       PARA_ERROR(ISDIR, "error: is a directory"), \
+       PARA_ERROR(NOENT, "no such file or directory"), \
+       PARA_ERROR(OPEN_PERM, "open error (permission denied)"), \
+       PARA_ERROR(MKDIR_PERM, "mkdir error (permission denied)"), \
+       PARA_ERROR(MKDIR, "failed to create directory"), \
+       PARA_ERROR(CHDIR, "failed to change directory"), \
+       PARA_ERROR(FCHDIR, "fchdir failed"), \
+       PARA_ERROR(OPENDIR, "can not open directory"), \
+       PARA_ERROR(NOSPC, "no space left on device"), \
+       PARA_ERROR(OPEN, "failed to open file"), \
 
 
 #define WRITE_ERRORS \
@@ -686,6 +687,7 @@ SS_ENUM(BLOB);
 SS_ENUM(PLAYLIST);
 SS_ENUM(SHA1);
 SS_ENUM(RBTREE);
+SS_ENUM(FSCK);
 /** \endcond */
 #undef PARA_ERROR
 /* rest of the world only sees the error text */
diff --git a/fade.c b/fade.c
index d9834a2b173eeffc2b3bc6744e20065ea2052647..38a6517cd0dbadc47671f00b7c0b3ba2052ec02c 100644 (file)
--- a/fade.c
+++ b/fade.c
@@ -6,6 +6,9 @@
 
 /** \file fade.c a volume fader and alarm clock */
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "fade.cmdline.h"
 #include "para.h"
 #include "fd.h"
diff --git a/fd.c b/fd.c
index 556f3e96c073b12de38496c595042616a96bafa0..398bf2ce818345a6cc3d98648953fa05096a8b48 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -6,11 +6,13 @@
 
 /** \file fd.c helper functions for file descriptor handling */
 
-#include "para.h"
+#include <sys/types.h>
+#include <dirent.h>
 #include <sys/mman.h>
 #include <fcntl.h>
 #include <sys/select.h>
 
+#include "para.h"
 #include "error.h"
 /**
  * check whether a file exists
@@ -134,7 +136,7 @@ again:
 }
 
 /**
- * *paraslash's wrapper for mmap
+ * Paraslash's wrapper for mmap.
  *
  * \param length number of bytes to mmap
  * \param prot either PROT_NONE or the bitwise OR of one or more of
@@ -157,3 +159,129 @@ void *para_mmap(size_t length, int prot, int flags, int fd, off_t offset)
        exit(EXIT_FAILURE);
 }
 
+/**
+ * Wrapper for the open(2) system call.
+ *
+ * \param path The filename.
+ * \param flags The usual open(2) flags.
+ * \param mode Specifies the permissions to use.
+ *
+ * The mode parameter must be specified when O_CREAT is in the flags, and is ignored
+ * otherwise.
+ *
+ * \return Positive on success, negative on errors.
+ *
+ * \sa open(2).
+ */
+int para_open(const char *path, int flags, mode_t mode)
+{
+       int ret = open(path, flags, mode);
+
+       if (ret >= 0)
+               return ret;
+       switch (errno) {
+       case EEXIST:
+               ret = -E_EXIST;
+               break;
+       case EISDIR:
+               ret = -E_ISDIR;
+               break;
+       case ENOENT:
+               ret = -E_NOENT;
+               break;
+       case EPERM:
+               ret = -E_OPEN_PERM;
+               break;
+       };
+       PARA_ERROR_LOG("failed to open %s: %s\n", path, strerror(errno));
+       return ret;
+}
+
+/**
+ * Save the cwd and open a given directory.
+ *
+ * \param dirname Path to the directory to open.
+ * \param dir Result pointer.
+ * \param cwd File descriptor of the current working directory.
+ *
+ * \return Positive on success, negative on errors.
+ *
+ * Opening the current directory (".") and calling fchdir() to return is
+ * usually faster and more reliable than saving cwd in some buffer and calling
+ * chdir() afterwards.
+ *
+ * If \a cwd is not \p NULL "." is opened and the resulting file descriptor is
+ * stored in \a cwd. If the function returns success, and \a cwd is not \p
+ * NULL, the caller must close this file descriptor (probably after calling
+ * fchdir(*cwd)).
+ *
+ * On errors, the function undos everything, so the caller needs neither close
+ * any files, nor change back to the original working directory.
+ *
+ * \sa getcwd(3).
+ *
+ */
+int para_opendir(const char *dirname, DIR **dir, int *cwd)
+{
+       int ret;
+
+       if (cwd) {
+               ret = para_open(".", O_RDONLY, 0);
+               if (ret < 0)
+                       return ret;
+               *cwd = ret;
+       }
+       ret = -E_CHDIR;
+       if (chdir(dirname) < 0)
+               goto close_cwd;
+       ret = -E_OPENDIR;
+       *dir = opendir(".");
+       if (!*dir)
+               goto change_to_orig_dir;
+       return 1;
+/* Ignore return value of fchdir() and close(). We're busted anyway. */
+change_to_orig_dir:
+       if (cwd)
+               fchdir(*cwd);
+close_cwd:
+       if (cwd)
+               close(*cwd);
+       return ret;
+}
+
+/**
+ * A wrapper for fchdir().
+ *
+ * \param fd An open file descriptor
+ *
+ * \return Positive on success, negative on errors.
+ */
+int para_fchdir(int fd)
+{
+       if (fchdir(fd) < 0)
+               return -E_FCHDIR;
+       return 1;
+}
+
+/**
+ * A wrapper for mkdir(2).
+ *
+ * \param path Name of the directory to create.
+ * \param mode The permissions to use.
+ *
+ * \return positive on success, negative on errors.
+ */
+int para_mkdir(const char *path, mode_t mode)
+{
+       if (!mkdir(path, mode))
+               return 1;
+       if (errno == EEXIST)
+               return -E_EXIST;
+       if (errno == ENOSPC)
+               return -E_NOSPC;
+       if (errno == ENOTDIR)
+               return -E_NOTDIR;
+       if (errno == EPERM)
+               return -E_MKDIR_PERM;
+       return -E_MKDIR;
+}
diff --git a/fd.h b/fd.h
index 9f5533432ff784711ee6aaf33cc1c20d5e9f6eed..9bbf7b57830fd5cd476d670e5129c550c3830cbb 100644 (file)
--- a/fd.h
+++ b/fd.h
@@ -13,3 +13,7 @@ int mark_fd_nonblock(int fd);
 void para_fd_set(int fd, fd_set *fds, int *max_fileno);
 __must_check int para_fgets(char *line, int size, FILE *f);
 void *para_mmap(size_t length, int prot, int flags, int fd, off_t offset);
+int para_open(const char *path, int flags, mode_t mode);
+int para_opendir(const char *dirname, DIR **dir, int *cwd);
+int para_mkdir(const char *path, mode_t mode);
+int para_fchdir(int fd);
index 89910345476e00c6f5737fe62e4d059aa02c45dd..50d3fae7651706cec291f6cbfc4eeb336ba214d0 100644 (file)
@@ -6,6 +6,9 @@
 
 /** \file file_write.c simple output plugin for testing purposes */
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "para.h"
 #include "list.h"
 #include "sched.h"
index b39874448668466c6b351871b56b681a25ee58e5..7852220a21c416c6c7e747549e7f3ee68d2baf5f 100644 (file)
@@ -6,6 +6,9 @@
 
 /** \file filter_chain.c common helper functions for filter input/output */
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "para.h"
 #include "list.h"
 #include "sched.h"
diff --git a/fsck.c b/fsck.c
index bc4083aed2cf988922a259e9a391f553eb96fc00..5f95b74fa1ed74dd5aca25e4bad749b42aa7068f 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -1,18 +1,25 @@
+/*
+ * Copyright (C) 1997-2007 Andre Noll <maan@systemlinux.org>
+ *
+ * Licensed under the GPL v2. For licencing details see COPYING.
+ */
+
+/** \file fsck.c The program used to check an osl table. */
+
+
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "para.h"
+#include "fd.h"
 #include "error.h"
 #include "osl_core.h"
+#include "fsck.cmdline.h"
 
-#define OSL_DUMP_DIR "/tmp/osldump"
-
-enum errors {
-       E_FSCK_SYNTAX = 501,
-       E_RANGE_VIOLATION,
-       E_NO_DS_FILE,
-       E_NOT_A_REGULAR_FILE,
-       E_BAD_HASH_PATH,
-};
+static struct fsck_args_info conf;
 
-INIT_STDERR_LOGGING(1);
+INIT_FSCK_ERRLISTS;
+INIT_STDERR_LOGGING(conf.loglevel_arg);
 
 /* taken from git */
 signed char hexval_table[256] = {
@@ -93,7 +100,8 @@ static int check_range(struct osl_table *t, uint32_t row_num, uint32_t col_num)
 //     PARA_INFO_LOG("obj: %p..%p\n", obj_start, obj_start + obj.size);
 //     PARA_INFO_LOG("map: %p..%p\n", map_start, map_start + col->data_map.size);
        if (obj_start < map_start || obj_start + obj.size > map_start + col->data_map.size) {
-               PARA_CRIT_LOG("row %u, col %u: range violation, very bad\n", row_num, col_num);
+               PARA_CRIT_LOG("range violation in row %u, col %u\n", row_num,
+                       col_num);
                return -E_RANGE_VIOLATION;
        }
        PARA_DEBUG_LOG("col %u: ok\n", col_num);
@@ -568,10 +576,6 @@ out:
        return ret;
 }
 
-#define FSCK 1
-#define FORCE 1
-#define DUMP 0
-
 static void set_dummy_contents(struct osl_table_description *desc)
 {
        int i;
@@ -603,7 +607,7 @@ static int fsck_init(struct osl_table_description *desc, struct osl_table **t)
        }
        PARA_INFO_LOG("unmapping index\n");
        para_munmap(map.data, map.size);
-       if (FORCE)
+       if (conf.force_given)
                ret = map_table(*t, (MAP_TBL_FL_IGNORE_DIRTY));
        else
                ret = map_table(*t, 0);
@@ -864,25 +868,89 @@ out:
        fsck_cleanup(t);
        return ret;
 }
-int main(__a_unused int argc, __a_unused char **argv)
+
+static int check_table(char *base_dir, char *table_name)
 {
+       struct osl_table_description desc = {
+               .column_descriptions = NULL,
+               .dir = base_dir,
+               .name = table_name
+       };
        int ret;
-       struct osl_table_description desc = {.column_descriptions = NULL};
 
-       ret = -E_FSCK_SYNTAX;
-       if (argc < 3)
-               goto out;
-       desc.dir = argv[1];
-       desc.name = argv[2];
-       if (FSCK) {
+       if (!conf.no_fsck_given) {
                ret = fsck(&desc);
                if (ret < 0)
-                       goto out;
+                       return ret;
+       }
+       if (!conf.dump_dir_given || !*conf.dump_dir_arg)
+               return 1;
+       return dump_table(conf.dump_dir_arg, &desc);
+}
+
+static int check_all_tables(char *base_dir)
+{
+       DIR *dir;
+       struct dirent *entry;
+       int cwd_fd, ret2, ret = para_opendir(base_dir, &dir, &cwd_fd);
+
+       if (ret < 0)
+               return ret;
+       while ((entry = readdir(dir))) {
+               mode_t m;
+               struct stat s;
+               if (!strcmp(entry->d_name, "."))
+                       continue;
+               if (!strcmp(entry->d_name, ".."))
+                       continue;
+               if (lstat(entry->d_name, &s) == -1)
+                       continue;
+               m = s.st_mode;
+               if (!S_ISDIR(m))
+                       continue;
+               ret = check_table(base_dir, entry->d_name);
+               if (ret < 0)
+                       break;
+       }
+       closedir(dir);
+       ret2 = para_fchdir(cwd_fd);
+       if (ret2 < 0 && ret >= 0)
+               ret = ret2;
+       close(cwd_fd);
+       return ret;
+}
+
+int main(__a_unused int argc, char **argv)
+{
+       int i, ret;
+       char *base_dir = NULL;
+
+       ret = fsck_cmdline_parser(argc, argv, &conf);
+       if (ret < 0) {
+               ret = -E_FSCK_SYNTAX;
+               goto out;
+       }
+       HANDLE_VERSION_FLAG("fsck", conf);
+       if (conf.base_dir_given)
+               base_dir = conf.base_dir_arg;
+       else {
+               char *home = para_homedir();
+               base_dir = make_message("%s/.paraslash/afs_database", home);
+               free(home);
+       }
+       if (!conf.inputs_num) {
+               ret = check_all_tables(base_dir);
+               goto out;
+       }
+       for (i = 0; i < conf.inputs_num; i++) {
+               ret = check_table(base_dir, conf.inputs[i]);
+               if (ret < 0)
+                       break;
        }
-       if (DUMP)
-               ret = dump_table(OSL_DUMP_DIR, &desc);
 out:
+       if (!conf.base_dir_given)
+               free(base_dir);
        if (ret < 0)
-               PARA_ERROR_LOG("error %d\n", ret);
-       return ret < 0? EXIT_FAILURE: EXIT_SUCCESS;
+               PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
+       return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;
 }
diff --git a/fsck.ggo b/fsck.ggo
new file mode 100644 (file)
index 0000000..207bc85
--- /dev/null
+++ b/fsck.ggo
@@ -0,0 +1,47 @@
+option "loglevel" l
+#~~~~~~~~~~~~~~~~~~
+
+"set loglevel (0-6)"
+
+       int typestr="level"
+       default="4"
+       optional
+
+option "base_dir" b
+#~~~~~~~~~~~~~~~~~~
+"Full path to the database directory
+containing the table(s) to be checked.
+(default='~/.paraslash/afs_database'"
+
+       string typestr="path"
+       optional
+
+option "dump_dir" d
+#~~~~~~~~~~~~~~~~~~
+"If path is non-empty, para_fsck will write a
+dump of all given tables to the specified
+path."
+
+       string typestr="path"
+       optional
+       default=""
+
+option "no_fsck" n
+#~~~~~~~~~~~~~~~~~
+"Disable fsck mode."
+
+       flag off
+
+option "force" f
+#~~~~~~~~~~~~~~~
+"Force fsck even if the table is dirty.
+Ignored if -n is given."
+
+       flag off
+
+option "dry_run" -
+#~~~~~~~~~~~~~~~~~
+"Only report problems, don't try to fix them."
+
+       flag off
+
index 11aed36a8b3608b17dcee9cf29178c2e0927c0dc..d842cb8a86e90f283729b25979d62971c3628c4b 100644 (file)
@@ -11,6 +11,9 @@
  * \sa filter_chain filter_chain_info filter
  */
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "para.h"
 #include "grab_client.cmdline.h"
 #include "list.h"
diff --git a/gui.c b/gui.c
index 28291a867fd99aea2f6d4abeb96c7e671abc8fc3..d8e200342fc991380445b6fa120ac2d2560bb05e 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -6,6 +6,9 @@
 
 /** \file gui.c ncurses-based interface for paraslash */
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "gui.cmdline.h"
 #include "para.h"
 #include "gui.h"
index 6ca226e6e0d468e953f3e1aac6cab52364f94ffb..dc3450a8410b3002e6a4e41f0a548d2f8efd8e9f 100644 (file)
@@ -1,3 +1,15 @@
+/*
+ * Copyright (C) 2006-2007 Andre Noll <maan@systemlinux.org>
+ *
+ * Licensed under the GPL v2. For licencing details see COPYING.
+ */
+
+/** \file gui_common.c Functions used by the guis of paraslash. */
+
+
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "para.h"
 #include "string.h"
 #include "fd.h"
index f82924d9cfd728c83f4bed516fc4e84dbe21e139..71aef76ad3bcd49e6eccb9d1221addb4884bc96d 100644 (file)
@@ -6,6 +6,9 @@
 
 /** \file http_recv.c paraslash's http receiver */
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "para.h"
 #include "error.h"
 #include "http.h"
index 8636d10d2d71e41419cd762328004e194f5ac7cb..3f03f00b41a943af347c2e5599fde1ff9a3e507d 100644 (file)
@@ -6,6 +6,8 @@
 
 /** \file http_send.c paraslash's http sender */
 
+#include <sys/types.h>
+#include <dirent.h>
 
 #include "para.h"
 #include "server.cmdline.h"
diff --git a/osl.c b/osl.c
index b1aaf3e5060b5f07ed9d61cbf02a2e0b66359510..ab3b8de4683df09c306bcd968ae868f2d978cc8d 100644 (file)
--- a/osl.c
+++ b/osl.c
@@ -5,13 +5,15 @@
  */
 
 /** \file osl.c Object storage layer functions. */
+#include <dirent.h> /* readdir() */
+#include <assert.h>
+
+
 #include "para.h"
 #include "error.h"
+#include "fd.h"
 #include "list.h"
 #include "osl_core.h"
-#include <dirent.h> /* readdir() */
-#include <assert.h>
-
 /**
  * A wrapper for lseek(2).
  *
@@ -93,46 +95,6 @@ ssize_t para_write_all(int fd, const void *buf, size_t size)
        }
        return 1;
 }
-/**
- * Wrapper for the open(2) system call.
- *
- * \param path The filename.
- * \param flags The usual open(2) flags.
- * \param mode Specifies the permissions to use.
- *
- * The mode parameter must be specified when O_CREAT is in the flags, and is ignored
- * otherwise.
- *
- * \return Positive on success, negative on errors. Possible errors: \p
- * E_EXIST, \p E_ISDIR, \p E_NOENT, \p E_OSL_PERM.
- *
- * \sa open(2).
- */
-int para_open(const char *path, int flags, mode_t mode)
-{
-       PARA_DEBUG_LOG("opening %s\n", path);
-       int ret = open(path, flags, mode);
-
-       if (ret >= 0)
-               return ret;
-       switch (errno) {
-       case EEXIST:
-               ret = -E_EXIST;
-               break;
-       case EISDIR:
-               ret = -E_ISDIR;
-               break;
-       case ENOENT:
-               ret = -E_NOENT;
-               break;
-       case EPERM:
-               ret = -E_OSL_PERM;
-               break;
-       };
-       PARA_ERROR_LOG("failed to open %s: %s\n", path, strerror(errno));
-       return ret;
-}
-
 /**
  * Open a file, write the given buffer and close the file.
  *
@@ -259,37 +221,22 @@ out:
 int for_each_file_in_dir(const char *dirname,
                int (*func)(const char *, const void *), const void *private_data)
 {
-       DIR *dir = NULL;
+       DIR *dir;
        struct dirent *entry;
-       /*
-        * Opening the current directory (".") and calling fchdir() to return
-        * is usually faster and more reliable than saving cwd in some buffer
-        * and calling chdir() afterwards (see man 3 getcwd).
-        */
-       int cwd_fd = open(".", O_RDONLY);
-       struct stat s;
-       int ret = -1;
-
-//     PARA_DEBUG_LOG("dirname: %s\n", dirname);
-       if (cwd_fd < 0)
-               return -E_OSL_GETCWD;
-       ret = -E_OSL_CHDIR;
-       if (chdir(dirname) < 0)
-               goto out;
-       ret = -E_OSL_OPENDIR;
-       dir = opendir(".");
-       if (!dir)
-               goto out;
+       int cwd_fd, ret2, ret = para_opendir(dirname, &dir, &cwd_fd);
+
+       if (ret < 0)
+               return ret;
        /* scan cwd recursively */
        while ((entry = readdir(dir))) {
                mode_t m;
                char *tmp;
+               struct stat s;
 
                if (!strcmp(entry->d_name, "."))
                        continue;
                if (!strcmp(entry->d_name, ".."))
                        continue;
-               ret = -E_OSL_LSTAT;
                if (lstat(entry->d_name, &s) == -1)
                        continue;
                m = s.st_mode;
@@ -311,29 +258,14 @@ int for_each_file_in_dir(const char *dirname,
        }
        ret = 1;
 out:
-       if (dir)
-               closedir(dir);
-       if (fchdir(cwd_fd) < 0 && ret >= 0)
-               ret = -E_OSL_CHDIR;
+       closedir(dir);
+       ret2 = para_fchdir(cwd_fd);
+       if (ret2 < 0 && ret >= 0)
+               ret = ret2;
        close(cwd_fd);
        return ret;
 }
 
-int para_mkdir(const char *path, mode_t mode)
-{
-       if (!mkdir(path, mode))
-               return 1;
-       if (errno == EEXIST)
-               return -E_EXIST;
-       if (errno == ENOSPC)
-               return -E_NOSPC;
-       if (errno == ENOTDIR)
-               return -E_NOTDIR;
-       if (errno == EPERM)
-               return E_OSL_PERM;
-       return -E_MKDIR;
-}
-
 static int verify_name(const char *name)
 {
        if (!name)
@@ -652,7 +584,7 @@ static int compare_table_descriptions(struct osl_table *t)
        ret = -E_BAD_TABLE_FLAGS;
        if (desc.flags != t->desc->flags)
                goto out;
-       ret = E_BAD_COLUMN_NUM;
+       ret = -E_BAD_COLUMN_NUM;
        if (desc.num_columns != t->desc->num_columns)
                goto out;
        FOR_EACH_COLUMN(i, t->desc, cd1) {
@@ -820,8 +752,7 @@ static void unmap_column(struct osl_table *t, unsigned col_num)
  * \param t Pointer to a mapped table.
  * \param flags Options for unmapping.
  *
- * \return Positive on success, negative on errors. Possible errors include:
- * E_NOT_MAPPED, E_MUNMAP.
+ * \return Positive on success, negative on errors.
  *
  * \sa map_table(), enum osl_close_flags, para_munmap().
  */
diff --git a/osl.h b/osl.h
index d787564f36b7e60f41fec0b1f0b8e0e38406accc..b0ad739101608f2ca9f3b853f5f2629ac9ed61e6 100644 (file)
--- a/osl.h
+++ b/osl.h
@@ -179,12 +179,10 @@ int osl_get_rank(const struct osl_table *t, struct osl_row *r,
 
 int for_each_file_in_dir(const char *dirname,
        int (*func)(const char *, const void *), const void *private_data);
-int para_open(const char *pathname, int flags, mode_t mode);
 int mmap_full_file(const char *filename, int open_mode, struct osl_object *obj);
 ssize_t para_write_all(int fd, const void *buf, size_t size);
 int para_lseek(int fd, off_t *offset, int whence);
 int para_write_file(const char *filename, const void *buf, size_t size);
-int para_mkdir(const char *path, mode_t mode);
 
 /**
  * A wrapper for munmap(2).
diff --git a/recv.c b/recv.c
index 423ccbc2c074bcd8a1f95a0c3614f3cbf4763d5b..3a3d142692aeab0018c13770d7eab1a94502cccc 100644 (file)
--- a/recv.c
+++ b/recv.c
@@ -6,8 +6,10 @@
 
 /** \file recv.c the stand-alone audio stream receiver */
 
-#include "para.h"
+#include <sys/types.h>
+#include <dirent.h>
 
+#include "para.h"
 #include "list.h"
 #include "sched.h"
 #include "recv.h"
diff --git a/sched.c b/sched.c
index 144eaf6e21a670d1243a07d00689cf6a3fbd1900..a7660f5972c9f678b6f3a19b7b4398a1e43ae24b 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -6,7 +6,10 @@
 
 /** \file sched.c paraslash's scheduling functions */
 
+#include <dirent.h> /* readdir() */
+#include <assert.h>
 #include <sys/time.h>
+
 #include "para.h"
 #include "ipc.h"
 #include "fd.h"
index d30aad80529d32b76f3015da3452daae3fcca4fe..c63f9b804b5e994926b5bb8f548747cdb96c95ad 100644 (file)
--- a/sdl_gui.c
+++ b/sdl_gui.c
@@ -6,6 +6,9 @@
 
 /** \file sdl_gui.c SDL-based interface for paraslash */
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "para.h"
 #include "gui_common.h"
 #include "fd.h"
index e94de736f81b9508739dbf0f4c38c180ede29fdb..d98e9603ced15a27ea1780ffb7ef850e5138c55e 100644 (file)
--- a/server.c
+++ b/server.c
@@ -15,6 +15,8 @@
  *
  */
 
+#include <sys/types.h>
+#include <dirent.h>
 
 #include "para.h"
 #include "server.cmdline.h"
index 0abe005c1a1fbea2b4cd30711b271a26fee27e57..bf0cd5ccff28286852858e1b4f22bf00f9436f7b 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -5,14 +5,14 @@
  */
 /** \file signal.c signal handling functions */
 
-
+#include <signal.h>
+#include <sys/types.h>
+#include <dirent.h>
 
 #include "para.h"
+#include "error.h"
 #include "fd.h"
 
-#include <signal.h>
-
-#include "error.h"
 static int signal_pipe[2];
 
 /**
diff --git a/stat.c b/stat.c
index 202dff8fc22970961ea1f2594e6c7db2f85c1965..ce6adeda2019454acfdf4ca5759e4a29cc4c2e64 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -8,6 +8,11 @@
  *  \file stat.c functions used for sending/receiving the status of para_server
  *  and para_audiod
  */
+
+
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "para.h"
 #include "close_on_fork.h"
 #include "list.h"
diff --git a/stdin.c b/stdin.c
index d9f9bd936590985bf32a8351738bbf875c4a5478..83ff48f50acf38a95c2f0b021a04edf48675c73c 100644 (file)
--- a/stdin.c
+++ b/stdin.c
@@ -6,6 +6,10 @@
 
 /** \file stdin.c functions that deal with reading from stdin */
 
+#include <dirent.h> /* readdir() */
+#include <assert.h>
+
+
 #include "para.h"
 #include "string.h"
 #include "list.h"
index 84f2f7cacd3935fd1f60245ff171cbd9f986607d..c616079139b2a41ace85e73aed7616257f0f550f 100644 (file)
--- a/stdout.c
+++ b/stdout.c
@@ -6,6 +6,9 @@
 
 /** \file stdout.c functions that deal with writing to stdout */
 
+#include <dirent.h> /* readdir() */
+#include <assert.h>
+
 #include "para.h"
 #include "string.h"
 #include "list.h"
index 18df94b4c117f0c1aab5093101d214a93e48cb87..8e21b238a26a0e7a4da29e0d210dfd64ecadf74d 100644 (file)
@@ -6,6 +6,9 @@
 
 /** \file user_list.c user handling for para_server */
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "para.h"
 #include "error.h"
 #include "fd.h"
diff --git a/vss.c b/vss.c
index 3ba5994b5123dd58573f6b049dd5420b23309ba3..e6cf59676fe4699b85501b5334de8c99b090a4f1 100644 (file)
--- a/vss.c
+++ b/vss.c
  * senders.
  */
 
+#include <sys/mman.h> /* mmap */
+#include <sys/time.h> /* gettimeofday */
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "para.h"
 #include "afh.h"
 #include "server.h"
-#include <sys/mman.h> /* mmap */
-#include <sys/time.h> /* gettimeofday */
 #include "server.cmdline.h"
 #include "afs_common.h"
 #include "vss.h"
diff --git a/write.c b/write.c
index 64c08d8b9e1412e7ed88c234609bc68173283049..a3b1de1c2ceefac4ac4d152cdf54df9658341d13 100644 (file)
--- a/write.c
+++ b/write.c
@@ -6,6 +6,9 @@
 
 /** \file write.c Paraslash's standalone wav/raw player */
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "para.h"
 #include "string.h"
 #include "write.cmdline.h"