summaryrefslogtreecommitdiff
path: root/jackd/controlapi.c
diff options
context:
space:
mode:
authortorben <torben@0c269be4-1314-0410-8aa9-9f06e86f4224>2011-05-29 00:46:17 +0000
committertorben <torben@0c269be4-1314-0410-8aa9-9f06e86f4224>2011-05-29 00:46:17 +0000
commitcd53c6bad4636e2cdfbf58f2b02dc5db736fc01d (patch)
tree8c213bd13f2f2d64c27290d909223f0265fe267b /jackd/controlapi.c
parenta84b9928ba6506a8625cceb9576675f6c10ad014 (diff)
downloadjack1-cd53c6bad4636e2cdfbf58f2b02dc5db736fc01d.tar.gz
[controlAPI] temporaily move jack_cleanup_files into controlapi.c
this function should probably go into engine.c git-svn-id: svn+ssh://jackaudio.org/trunk/jack@4408 0c269be4-1314-0410-8aa9-9f06e86f4224
Diffstat (limited to 'jackd/controlapi.c')
-rw-r--r--jackd/controlapi.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/jackd/controlapi.c b/jackd/controlapi.c
index be473ee..0f9b530 100644
--- a/jackd/controlapi.c
+++ b/jackd/controlapi.c
@@ -418,6 +418,71 @@ jack_drivers_load ()
return driver_list;
}
+static void
+jack_cleanup_files (const char *server_name)
+{
+ DIR *dir;
+ struct dirent *dirent;
+ char dir_name[PATH_MAX+1] = "";
+ jack_server_dir (server_name, dir_name);
+
+ /* On termination, we remove all files that jackd creates so
+ * subsequent attempts to start jackd will not believe that an
+ * instance is already running. If the server crashes or is
+ * terminated with SIGKILL, this is not possible. So, cleanup
+ * is also attempted when jackd starts.
+ *
+ * There are several tricky issues. First, the previous JACK
+ * server may have run for a different user ID, so its files
+ * may be inaccessible. This is handled by using a separate
+ * JACK_TMP_DIR subdirectory for each user. Second, there may
+ * be other servers running with different names. Each gets
+ * its own subdirectory within the per-user directory. The
+ * current process has already registered as `server_name', so
+ * we know there is no other server actively using that name.
+ */
+
+ /* nothing to do if the server directory does not exist */
+ if ((dir = opendir (dir_name)) == NULL) {
+ return;
+ }
+
+ /* unlink all the files in this directory, they are mine */
+ while ((dirent = readdir (dir)) != NULL) {
+
+ char fullpath[PATH_MAX+1];
+
+ if ((strcmp (dirent->d_name, ".") == 0)
+ || (strcmp (dirent->d_name, "..") == 0)) {
+ continue;
+ }
+
+ snprintf (fullpath, sizeof (fullpath), "%s/%s",
+ dir_name, dirent->d_name);
+
+ if (unlink (fullpath)) {
+ jack_error ("cannot unlink `%s' (%s)", fullpath,
+ strerror (errno));
+ }
+ }
+
+ closedir (dir);
+
+ /* now, delete the per-server subdirectory, itself */
+ if (rmdir (dir_name)) {
+ jack_error ("cannot remove `%s' (%s)", dir_name,
+ strerror (errno));
+ }
+
+ /* finally, delete the per-user subdirectory, if empty */
+ if (rmdir (jack_user_dir ())) {
+ if (errno != ENOTEMPTY) {
+ jack_error ("cannot remove `%s' (%s)",
+ jack_user_dir (), strerror (errno));
+ }
+ }
+}
+
static int
jackctl_drivers_load(
struct jackctl_server * server_ptr)