Skip to content

Commit 9703d68

Browse files
authored
Move print socket to XDG_RUNTIME_DIR (#60)
We should not create unwanted directories in the user's HOME directory. XDG_RUNTIME_DIR is the standard location to place user sockets in; it is a tmpfs generally mounted at /run/user/<uid>.
1 parent 56a1596 commit 9703d68

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

src/backend_helper.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,27 +1453,23 @@ void print_socket(PrinterCUPS *p, int num_settings, GVariant *settings,
14531453
sizeof(socket_option));
14541454

14551455
// Create base directories
1456-
char *home = getenv("HOME");
1457-
if (home == NULL) {
1458-
logwarn("HOME environment variable not set\n");
1459-
close(socket_fd);
1460-
cupsFreeOptions(num_options, options);
1461-
return;
1456+
const char *base = getenv("XDG_RUNTIME_DIR");
1457+
if (base == NULL) {
1458+
base = getenv("HOME");
1459+
if (base == NULL) {
1460+
logwarn("Both HOME and XDG_RUNTIME_DIR environment variables are not set\n");
1461+
close(socket_fd);
1462+
cupsFreeOptions(num_options, options);
1463+
return;
1464+
}
14621465
}
1463-
char base_dir[256];
1464-
char socket_dir[512];
1465-
14661466

1467-
snprintf(base_dir, sizeof(base_dir), "%s/cpdb" , home);
1468-
if(mkdir(base_dir, 0700) == -1 && errno != EEXIST){
1467+
char socket_dir[512];
1468+
snprintf(socket_dir, sizeof(socket_dir), "%s/cpdb" , base);
1469+
if(mkdir(socket_dir, 0700) == -1 && errno != EEXIST){
14691470
logwarn("Error creating base directory");
14701471
}
14711472

1472-
snprintf(socket_dir, sizeof(socket_dir), "%s/sockets", base_dir);
1473-
if(mkdir(socket_dir, 0700) == -1 && errno != EEXIST){
1474-
logwarn("Error creating sockets directory");
1475-
}
1476-
14771473
// Create the CUPS JOB
14781474
int job_id = 0;
14791475
if(cupsCreateDestJob(CUPS_HTTP_DEFAULT, p->dest, p->dinfo, &job_id, title,

0 commit comments

Comments
 (0)