annotate dpid/dpi_socket_dir.c @ 2048:5060d415a85a

clickable menu items (even those introducing submenus) MUST have callbacks I clicked on the "Panel size" item itself instead of any of the options in its submenu, and: Segfault!
author corvid <corvid@lavabit.com>
date Thu, 26 May 2011 02:51:18 +0000
parents d7dbd3dcfa38
children
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 Copyright (C) 2003 Ferdi Franceschini <ferdif@optusnet.com.au>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
7 (at your option) any later version.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12 GNU General Public License for more details.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
972
d7dbd3dcfa38 Updated the GPL copyright note in the source files
Detlef Riekenberg <wine.dev@web.de>
parents: 302
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
16 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
17
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18 /*! \file
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19 * Create a per user temporary directory for dpi sockets
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22 #include <errno.h>
10
f30c923e31aa Fixed a problem with locally-installed dpis.
jcid
parents: 0
diff changeset
23 #include <stdlib.h>
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
24 #include "dpid_common.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25 #include "dpi.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26 #include "misc_new.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27 #include "dpi_socket_dir.h" /* for function prototypes */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29 /*! Save socket directory name in ~/.dillo/dpi_socket_dir
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30 * \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31 * \li 1 on success
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32 * \li -1 on failure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
33 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
34 int w_dpi_socket_dir(char *dirname, char *sockdir)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
35 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
36 FILE *dir;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
37
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
38 if ((dir = fopen(dirname, "w")) == NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
39 ERRMSG("w_dpi_socket_dir", "fopen", errno);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
40 return (-1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
41 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
42 fprintf(dir, "%s", sockdir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
43 fclose(dir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
44 return (1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
45 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
46
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47 /*! Test that socket directory exists and is a directory
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48 * \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49 * \li 1 on success
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50 * \li 0 on failure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51 * \bug Does not check permissions or that it's a symbolic link
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
52 * to another directory.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
53 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
54 int tst_dir(char *dir)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
56 char *dirtest;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
57 int ret = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
58
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
59 /* test for a directory */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
60 dirtest = dStrconcat(dir, "/", NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
61 if (access(dirtest, F_OK) == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
62 ERRMSG("tst_dir", "access", errno);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
63 MSG_ERR(" - %s\n", dirtest);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
64 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
65 ret = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
66 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
67 dFree(dirtest);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
68
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
69 return ret;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
70 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
71
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
72 /*! Create socket directory
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
73 * \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
74 * \li Socket directory path on success
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
75 * \li NULL on failure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
76 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
77 char *mk_sockdir(void)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
78 {
10
f30c923e31aa Fixed a problem with locally-installed dpis.
jcid
parents: 0
diff changeset
79 char *template, *logname;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
80
282
87f5a4a8c91b - Minor cleanups.
jcid
parents: 10
diff changeset
81 logname = getenv("LOGNAME") ? getenv("LOGNAME") : "dillo";
10
f30c923e31aa Fixed a problem with locally-installed dpis.
jcid
parents: 0
diff changeset
82 template = dStrconcat("/tmp/", logname, "-", "XXXXXX", NULL);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
83 if (a_Misc_mkdtemp(template) == NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
84 ERRMSG("mk_sockdir", "a_Misc_mkdtemp", 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
85 MSG_ERR(" - %s\n", template);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
86 dFree(template);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
87 return (NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
88 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
89 return template;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
90 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
91
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
92 /*! Create socket directory if it does not exist and save its name in
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
93 * ~/.dillo/dpi_socket_dir.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
94 * \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
95 * \li Socket directory name on success
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
96 * \li NULL on failure.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
97 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
98 char *init_sockdir(char *dpi_socket_dir)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
99 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
100 char *sockdir = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
101 int dir_ok = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
102
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
103 if ((sockdir = a_Dpi_rd_dpi_socket_dir(dpi_socket_dir)) == NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
104 MSG_ERR("init_sockdir: The dpi_socket_dir file %s does not exist\n",
302
43c1c1cc33d1 - Fixed a small printf error.
jcid
parents: 282
diff changeset
105 dpi_socket_dir);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
106 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
107 if ((dir_ok = tst_dir(sockdir)) == 1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
108 MSG_ERR("init_sockdir: The socket directory %s exists and is OK\n",
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
109 sockdir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
110 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
111 MSG_ERR("init_sockdir: The socket directory %s does not exist "
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
112 "or is not a directory\n", sockdir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
113 dFree(sockdir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
114 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
115 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
116 if (!dir_ok) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
117 sockdir = mk_sockdir();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
118 if (sockdir == NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
119 ERRMSG("init_sockdir", "mk_sockdir", 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
120 MSG_ERR(" - Failed to create dpi socket directory\n");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
121 } else if ((w_dpi_socket_dir(dpi_socket_dir, sockdir)) == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
122 ERRMSG("init_sockdir", "w_dpi_socket_dir", 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
123 MSG_ERR(" - failed to save %s\n", sockdir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
124 dFree(sockdir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
125 sockdir = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
126 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
127 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
128 return (sockdir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
129 }