File plan-1.10.1-lockdir.diff of Package plan

Index: plan-1.10.1/src/config.h
===================================================================
--- plan-1.10.1.orig/src/config.h
+++ plan-1.10.1/src/config.h
@@ -17,10 +17,10 @@
  */
 
 #ifndef PLANLOCK			 /* defaults for cc -D options */
-#define PLANLOCK	/tmp/.plan%d
+#define PLANLOCK	.planlock
 #endif
 #ifndef PLANDLOCK			 /* defaults for cc -D options */
-#define PLANDLOCK	/tmp/.pland%d
+#define PLANDLOCK	.plandlock
 #endif
 #ifndef DOFORK				 /* is -f or -F default? */
 #define DOFORK		TRUE
Index: plan-1.10.1/src/daemon.c
===================================================================
--- plan-1.10.1.orig/src/daemon.c
+++ plan-1.10.1/src/daemon.c
@@ -264,7 +264,7 @@ int main(
 #else
 		sleep(twait);
 #endif
-		refresh_lock(resolve_tilde(PLANDLOCK));
+		refresh_lock();
 		logged_in = FALSE;
 		if (pw) {
 #if defined(SUN) || defined(BSD) || defined(__FreeBSD__)
Index: plan-1.10.1/src/main.c
===================================================================
--- plan-1.10.1.orig/src/main.c
+++ plan-1.10.1/src/main.c
@@ -326,7 +326,7 @@ static void non_interactive(
 	time_t		trigger;		/* trigger date and time */
 	char		msg[1024];		/* note from command line */
 	int		n, i, j;		/* char and arg counters */
-	char		lockfile[80];		/* plan lockfile, for sighup */
+	char		lockfile[4096];		/* plan lockfile, for sighup */
 	char		*flags;			/* where to hide reminder */
 	FILE		*fp;			/* for reading lockfile */
 	PID_T		pid = 0;		/* interactive plan PID */
@@ -454,7 +454,7 @@ static void non_interactive(
 	printf("%s %s \"%.57s\"\n", mkdatestring(trigger),
 				    mktimestring(trigger, FALSE), msg);
 	fflush(stdout);
-	sprintf(lockfile, resolve_tilde(PLANLOCK), (int)getuid());
+	snprintf(lockfile, sizeof(lockfile), "/%s/%s", getenv("XDG_RUNTIME_DIR"), PLANLOCK);
 	if ((fp = fopen(lockfile, "r"))) {
 		fscanf(fp, "%d", &pid);
 		if (pid > 1)
@@ -935,11 +935,11 @@ static PID_T		daemon_pid;	/* process ID
 static void init_daemon(void)
 {
 	int			i, lockfd;	/* lockfile descriptor */
-	char			path[256];	/* lockfile path */
+	char			path[4096];	/* lockfile path */
 	char			buf[12];	/* contents of file (pid) */
 
 	daemon_pid = 0;
-	sprintf(path, resolve_tilde(PLANDLOCK), (int)getuid());
+	snprintf(path, sizeof(path), "/%s/%s", getenv("XDG_RUNTIME_DIR"), PLANDLOCK);
 	if ((lockfd = open(path, O_RDONLY)) < 0) {
 		if (rundaemon) {
 			run_daemon(0);
Index: plan-1.10.1/src/proto.h
===================================================================
--- plan-1.10.1.orig/src/proto.h
+++ plan-1.10.1/src/proto.h
@@ -234,8 +234,7 @@ extern BOOL find_file(			/* find file <n
 extern BOOL startup_lock(		/* make sure program runs only once */
 	BOOL		pland,		/* is this plan or pland? */
 	BOOL		force);		/* kill competitor */
-extern BOOL refresh_lock(
-	char		*pathtmp);	/* PLANDLOCK or PLANLOCK */
+extern BOOL refresh_lock(void);
 extern void lockfile(
 	FILE		*fp,		/* file to lock */
 	BOOL		lock);		/* TRUE=lock, FALSE=unlock */
Index: plan-1.10.1/src/util.c
===================================================================
--- plan-1.10.1.orig/src/util.c
+++ plan-1.10.1/src/util.c
@@ -56,7 +56,7 @@ extern struct passwd *getpwnam();
 
 extern char		*progname;	/* argv[0] */
 extern struct plist	*mainlist;	/* list of all schedule entries */
-char			lockpath[256];	/* lockfile path */
+char			lockpath[4096];	/* lockfile path */
 
 
 /*
@@ -175,16 +175,12 @@ BOOL startup_lock(
 	BOOL			pland,		/* is this plan or pland? */
 	BOOL			force)		/* kill competitor */
 {
-	char			*pathtmp;	/* name of lockfile */
 	char			buf[2048];	/* lockfile contents */
 	int			lockfd;		/* lock/pid file */
 	PID_T			pid;		/* pid in lockfile */
 	int			retry = 5;	/* try to kill daemon 5 times*/
 
-	pathtmp = resolve_tilde(pland ? PLANDLOCK : PLANLOCK);
-	sprintf(buf, pathtmp, (int)getuid());
-	strncpy(lockpath, resolve_tilde(buf), sizeof(lockpath)-1);
-	lockpath[sizeof(lockpath)-1] = 0;
+	snprintf(lockpath, sizeof(lockpath), "/%s/%s", getenv("XDG_RUNTIME_DIR"), pland?PLANDLOCK:PLANLOCK);
 	while ((lockfd = open(lockpath, O_WRONLY|O_EXCL|O_CREAT, 0644)) < 0) {
 		if ((lockfd = open(lockpath, O_RDONLY)) < 0) {
 			int err = errno;
@@ -234,8 +230,8 @@ BOOL startup_lock(
 		   !check_process(pland, pid)) {
 			fprintf(stderr, _("%s: process %d owning lockfile %s "
 				"no longer exists, not killing"),
-				progname, pid, pathtmp);
-			unlink(pathtmp);
+				progname, pid, lockpath);
+			unlink(lockpath);
 			break;
 		}
 		(void)kill(pid, retry == 4 ? SIGINT : SIGTERM);
@@ -302,13 +298,11 @@ static BOOL check_process(
  * Create new lock file when it has been deleted (after cleanup of /tmp)
  */
 
-BOOL refresh_lock(
-	char		*pathtmp)	/* PLANDLOCK or PLANLOCK */
+BOOL refresh_lock()
 {
 	char		buf[80];	/* lockfile contents */
 	int		lockfd;		/* lock/pid file */
 
-	sprintf(lockpath, pathtmp, (int)getuid());
 	if ((lockfd = open(lockpath, O_RDONLY)) >= 0) {
 		close(lockfd);
 		return(TRUE);
Index: plan-1.10.1/src/Makefile
===================================================================
--- plan-1.10.1.orig/src/Makefile
+++ plan-1.10.1/src/Makefile
@@ -24,9 +24,9 @@ CATMAN=/usr/catman/local/cat
 #				# subdirectory in home dir, or empty
 PLANRULE=
 #				# lockfile for plan, %d is uid
-PLANLOCK="/tmp/.plan%d"
+PLANLOCK=".planlock"
 #				# lockfile for pland, %d is uid
-PLANDLOCK="/tmp/.pland%d"
+PLANDLOCK=".plandlock"
 #				# extra cc options, e.g. "-I/var/include"
 INCDIR=
 #				# standard Unix lexer