3 * Fvwm command input interface.
5 * Copyright 1998, Toshi Isogai.
6 * Use this program at your own risk.
7 * Permission to use this program for any purpose is given,
8 * as long as the copyright is kept intact.
12 /* This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include "FvwmCommand.h"
30 #define MAXHOSTNAME 32
32 char * fifos_get_default_name(void)
34 char file_suffix
[] = { 'R', 'C', 'M', '\0' };
41 char hostname
[MAXHOSTNAME
];
47 dpy_name
= getenv("DISPLAY");
48 if (!dpy_name
|| *dpy_name
== 0)
52 if (strncmp(dpy_name
, "unix:", 5) == 0)
57 c
= strrchr(dpy_name
, '.');
63 for (c
++, i
= 0; isdigit(*c
); c
++, i
++)
70 /* cut off trailing period */
76 /* append screen number */
77 strcpy(dpy_name_add
, ".0");
79 f_stem
= safemalloc(11 + strlen(F_NAME
) + MAXHOSTNAME
+
80 strlen(dpy_name
) + strlen(dpy_name_add
));
83 (stat("/var/tmp", &stat_buf
) == 0) &&
84 (stat_buf
.st_mode
& S_IFDIR
))
86 strcpy (f_stem
, "/var/tmp/");
90 strcpy (f_stem
, "/tmp/");
92 strcat(f_stem
, F_NAME
);
95 if (!dpy_name
[0] || ':' == dpy_name
[0])
97 /* Put hostname before dpy if not there */
98 gethostname(hostname
, MAXHOSTNAME
);
99 strcat(f_stem
, hostname
);
101 strcat(f_stem
, dpy_name
);
102 strcat(f_stem
, dpy_name_add
);
104 /* Verify that all files are either non-symlinks owned by the current
105 * user or non-existing. If not: use FVWM_USERDIR as base instead. */
107 type_pos
= strlen(f_stem
);
109 is_path_valid
= True
;
111 f_stem
[type_pos
+1] = 0;
113 for (c
= file_suffix
; *c
!= 0 && is_path_valid
; c
++)
117 f_stem
[type_pos
] = *c
;
120 rc
= fvwm_lstat(f_stem
, &stat_buf
);
124 rc
= stat(f_stem
, &stat_buf
);
128 /* stat successful */
130 stat_buf
.st_uid
!= owner
||
131 stat_buf
.st_nlink
> 1 ||
132 S_ISDIR(stat_buf
.st_mode
) ||
133 FVWM_S_ISLNK(stat_buf
.st_mode
) ||
134 (stat_buf
.st_mode
& FVWM_S_IFLNK
) != 0)
136 is_path_valid
= False
;
140 else if (errno
!= ENOENT
)
142 is_path_valid
= False
;
145 f_stem
[type_pos
] = 0;
153 if (f_stem
[1] == 't') /* /tmp/ */
155 tailname
= f_stem
+ 4;
159 tailname
= f_stem
+ 8;
162 userdir
= getenv("FVWM_USERDIR");
168 f_stem
= safemalloc(strlen(userdir
) + strlen(tailname
) + 1);
169 strcpy(f_stem
, userdir
);
170 strcat(f_stem
, tailname
);