void verboselog(char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
+/**
+ * Deletes the unused log files. Useful if i3 exits immediately, eg.
+ * because --get-socketpath was called. We don't care for syscall
+ * failures. This function is invoked automatically when exiting.
+ */
+void purge_zerobyte_logfile(void);
+
#endif
loglastwrap = logbuffer + logbuffer_size;
store_log_markers();
}
+ atexit(purge_zerobyte_logfile);
}
/*
vlog(debug_logging, fmt, args);
va_end(args);
}
+
+/*
+ * Deletes the unused log files. Useful if i3 exits immediately, eg.
+ * because --get-socketpath was called. We don't care for syscall
+ * failures. This function is invoked automatically when exiting.
+ */
+void purge_zerobyte_logfile(void) {
+ struct stat st;
+ char *slash;
+
+ if (!errorfilename)
+ return;
+
+ /* don't delete the log file if it contains something */
+ if ((stat(errorfilename, &st)) == -1 || st.st_size > 0)
+ return;
+
+ if (unlink(errorfilename) == -1)
+ return;
+
+ if ((slash = strrchr(errorfilename, '/')) != NULL) {
+ *slash = '\0';
+ /* possibly fails with ENOTEMPTY if there are files (or
+ * sockets) left. */
+ rmdir(errorfilename);
+ }
+}
char *socket_path = root_atom_contents("I3_SOCKET_PATH");
if (socket_path) {
printf("%s\n", socket_path);
- return 0;
+ exit(EXIT_SUCCESS);
}
- return 1;
+ exit(EXIT_FAILURE);
} else if (strcmp(long_options[option_index].name, "shmlog-size") == 0 ||
strcmp(long_options[option_index].name, "shmlog_size") == 0) {
shmlog_size = atoi(optarg);