xref: /OK3568_Linux_fs/kernel/arch/um/os-Linux/umid.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun #include <stdio.h>
7*4882a593Smuzhiyun #include <stdlib.h>
8*4882a593Smuzhiyun #include <dirent.h>
9*4882a593Smuzhiyun #include <errno.h>
10*4882a593Smuzhiyun #include <fcntl.h>
11*4882a593Smuzhiyun #include <signal.h>
12*4882a593Smuzhiyun #include <string.h>
13*4882a593Smuzhiyun #include <unistd.h>
14*4882a593Smuzhiyun #include <sys/stat.h>
15*4882a593Smuzhiyun #include <init.h>
16*4882a593Smuzhiyun #include <os.h>
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #define UML_DIR "~/.uml/"
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #define UMID_LEN 64
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /* Changed by set_umid, which is run early in boot */
23*4882a593Smuzhiyun static char umid[UMID_LEN] = { 0 };
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun /* Changed by set_uml_dir and make_uml_dir, which are run early in boot */
26*4882a593Smuzhiyun static char *uml_dir = UML_DIR;
27*4882a593Smuzhiyun 
make_uml_dir(void)28*4882a593Smuzhiyun static int __init make_uml_dir(void)
29*4882a593Smuzhiyun {
30*4882a593Smuzhiyun 	char dir[512] = { '\0' };
31*4882a593Smuzhiyun 	int len, err;
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun 	if (*uml_dir == '~') {
34*4882a593Smuzhiyun 		char *home = getenv("HOME");
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun 		err = -ENOENT;
37*4882a593Smuzhiyun 		if (home == NULL) {
38*4882a593Smuzhiyun 			printk(UM_KERN_ERR
39*4882a593Smuzhiyun 				"%s: no value in environment for $HOME\n",
40*4882a593Smuzhiyun 				__func__);
41*4882a593Smuzhiyun 			goto err;
42*4882a593Smuzhiyun 		}
43*4882a593Smuzhiyun 		strlcpy(dir, home, sizeof(dir));
44*4882a593Smuzhiyun 		uml_dir++;
45*4882a593Smuzhiyun 	}
46*4882a593Smuzhiyun 	strlcat(dir, uml_dir, sizeof(dir));
47*4882a593Smuzhiyun 	len = strlen(dir);
48*4882a593Smuzhiyun 	if (len > 0 && dir[len - 1] != '/')
49*4882a593Smuzhiyun 		strlcat(dir, "/", sizeof(dir));
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun 	err = -ENOMEM;
52*4882a593Smuzhiyun 	uml_dir = malloc(strlen(dir) + 1);
53*4882a593Smuzhiyun 	if (uml_dir == NULL) {
54*4882a593Smuzhiyun 		printk(UM_KERN_ERR "%s : malloc failed, errno = %d\n",
55*4882a593Smuzhiyun 			__func__, errno);
56*4882a593Smuzhiyun 		goto err;
57*4882a593Smuzhiyun 	}
58*4882a593Smuzhiyun 	strcpy(uml_dir, dir);
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun 	if ((mkdir(uml_dir, 0777) < 0) && (errno != EEXIST)) {
61*4882a593Smuzhiyun 		printk(UM_KERN_ERR "Failed to mkdir '%s': %s\n",
62*4882a593Smuzhiyun 			uml_dir, strerror(errno));
63*4882a593Smuzhiyun 		err = -errno;
64*4882a593Smuzhiyun 		goto err_free;
65*4882a593Smuzhiyun 	}
66*4882a593Smuzhiyun 	return 0;
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun err_free:
69*4882a593Smuzhiyun 	free(uml_dir);
70*4882a593Smuzhiyun err:
71*4882a593Smuzhiyun 	uml_dir = NULL;
72*4882a593Smuzhiyun 	return err;
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun /*
76*4882a593Smuzhiyun  * Unlinks the files contained in @dir and then removes @dir.
77*4882a593Smuzhiyun  * Doesn't handle directory trees, so it's not like rm -rf, but almost such. We
78*4882a593Smuzhiyun  * ignore ENOENT errors for anything (they happen, strangely enough - possibly
79*4882a593Smuzhiyun  * due to races between multiple dying UML threads).
80*4882a593Smuzhiyun  */
remove_files_and_dir(char * dir)81*4882a593Smuzhiyun static int remove_files_and_dir(char *dir)
82*4882a593Smuzhiyun {
83*4882a593Smuzhiyun 	DIR *directory;
84*4882a593Smuzhiyun 	struct dirent *ent;
85*4882a593Smuzhiyun 	int len;
86*4882a593Smuzhiyun 	char file[256];
87*4882a593Smuzhiyun 	int ret;
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun 	directory = opendir(dir);
90*4882a593Smuzhiyun 	if (directory == NULL) {
91*4882a593Smuzhiyun 		if (errno != ENOENT)
92*4882a593Smuzhiyun 			return -errno;
93*4882a593Smuzhiyun 		else
94*4882a593Smuzhiyun 			return 0;
95*4882a593Smuzhiyun 	}
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun 	while ((ent = readdir(directory)) != NULL) {
98*4882a593Smuzhiyun 		if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
99*4882a593Smuzhiyun 			continue;
100*4882a593Smuzhiyun 		len = strlen(dir) + strlen("/") + strlen(ent->d_name) + 1;
101*4882a593Smuzhiyun 		if (len > sizeof(file)) {
102*4882a593Smuzhiyun 			ret = -E2BIG;
103*4882a593Smuzhiyun 			goto out;
104*4882a593Smuzhiyun 		}
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun 		sprintf(file, "%s/%s", dir, ent->d_name);
107*4882a593Smuzhiyun 		if (unlink(file) < 0 && errno != ENOENT) {
108*4882a593Smuzhiyun 			ret = -errno;
109*4882a593Smuzhiyun 			goto out;
110*4882a593Smuzhiyun 		}
111*4882a593Smuzhiyun 	}
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun 	if (rmdir(dir) < 0 && errno != ENOENT) {
114*4882a593Smuzhiyun 		ret = -errno;
115*4882a593Smuzhiyun 		goto out;
116*4882a593Smuzhiyun 	}
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun 	ret = 0;
119*4882a593Smuzhiyun out:
120*4882a593Smuzhiyun 	closedir(directory);
121*4882a593Smuzhiyun 	return ret;
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun /*
125*4882a593Smuzhiyun  * This says that there isn't already a user of the specified directory even if
126*4882a593Smuzhiyun  * there are errors during the checking.  This is because if these errors
127*4882a593Smuzhiyun  * happen, the directory is unusable by the pre-existing UML, so we might as
128*4882a593Smuzhiyun  * well take it over.  This could happen either by
129*4882a593Smuzhiyun  * 	the existing UML somehow corrupting its umid directory
130*4882a593Smuzhiyun  * 	something other than UML sticking stuff in the directory
131*4882a593Smuzhiyun  *	this boot racing with a shutdown of the other UML
132*4882a593Smuzhiyun  * In any of these cases, the directory isn't useful for anything else.
133*4882a593Smuzhiyun  *
134*4882a593Smuzhiyun  * Boolean return: 1 if in use, 0 otherwise.
135*4882a593Smuzhiyun  */
is_umdir_used(char * dir)136*4882a593Smuzhiyun static inline int is_umdir_used(char *dir)
137*4882a593Smuzhiyun {
138*4882a593Smuzhiyun 	char pid[sizeof("nnnnnnnnn")], *end, *file;
139*4882a593Smuzhiyun 	int dead, fd, p, n, err;
140*4882a593Smuzhiyun 	size_t filelen = strlen(dir) + sizeof("/pid") + 1;
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun 	file = malloc(filelen);
143*4882a593Smuzhiyun 	if (!file)
144*4882a593Smuzhiyun 		return -ENOMEM;
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun 	snprintf(file, filelen, "%s/pid", dir);
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun 	dead = 0;
149*4882a593Smuzhiyun 	fd = open(file, O_RDONLY);
150*4882a593Smuzhiyun 	if (fd < 0) {
151*4882a593Smuzhiyun 		fd = -errno;
152*4882a593Smuzhiyun 		if (fd != -ENOENT) {
153*4882a593Smuzhiyun 			printk(UM_KERN_ERR "is_umdir_used : couldn't open pid "
154*4882a593Smuzhiyun 			       "file '%s', err = %d\n", file, -fd);
155*4882a593Smuzhiyun 		}
156*4882a593Smuzhiyun 		goto out;
157*4882a593Smuzhiyun 	}
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	err = 0;
160*4882a593Smuzhiyun 	n = read(fd, pid, sizeof(pid));
161*4882a593Smuzhiyun 	if (n < 0) {
162*4882a593Smuzhiyun 		printk(UM_KERN_ERR "is_umdir_used : couldn't read pid file "
163*4882a593Smuzhiyun 		       "'%s', err = %d\n", file, errno);
164*4882a593Smuzhiyun 		goto out_close;
165*4882a593Smuzhiyun 	} else if (n == 0) {
166*4882a593Smuzhiyun 		printk(UM_KERN_ERR "is_umdir_used : couldn't read pid file "
167*4882a593Smuzhiyun 		       "'%s', 0-byte read\n", file);
168*4882a593Smuzhiyun 		goto out_close;
169*4882a593Smuzhiyun 	}
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 	p = strtoul(pid, &end, 0);
172*4882a593Smuzhiyun 	if (end == pid) {
173*4882a593Smuzhiyun 		printk(UM_KERN_ERR "is_umdir_used : couldn't parse pid file "
174*4882a593Smuzhiyun 		       "'%s', errno = %d\n", file, errno);
175*4882a593Smuzhiyun 		goto out_close;
176*4882a593Smuzhiyun 	}
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun 	if ((kill(p, 0) == 0) || (errno != ESRCH)) {
179*4882a593Smuzhiyun 		printk(UM_KERN_ERR "umid \"%s\" is already in use by pid %d\n",
180*4882a593Smuzhiyun 		       umid, p);
181*4882a593Smuzhiyun 		return 1;
182*4882a593Smuzhiyun 	}
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun out_close:
185*4882a593Smuzhiyun 	close(fd);
186*4882a593Smuzhiyun out:
187*4882a593Smuzhiyun 	free(file);
188*4882a593Smuzhiyun 	return 0;
189*4882a593Smuzhiyun }
190*4882a593Smuzhiyun 
191*4882a593Smuzhiyun /*
192*4882a593Smuzhiyun  * Try to remove the directory @dir unless it's in use.
193*4882a593Smuzhiyun  * Precondition: @dir exists.
194*4882a593Smuzhiyun  * Returns 0 for success, < 0 for failure in removal or if the directory is in
195*4882a593Smuzhiyun  * use.
196*4882a593Smuzhiyun  */
umdir_take_if_dead(char * dir)197*4882a593Smuzhiyun static int umdir_take_if_dead(char *dir)
198*4882a593Smuzhiyun {
199*4882a593Smuzhiyun 	int ret;
200*4882a593Smuzhiyun 	if (is_umdir_used(dir))
201*4882a593Smuzhiyun 		return -EEXIST;
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun 	ret = remove_files_and_dir(dir);
204*4882a593Smuzhiyun 	if (ret) {
205*4882a593Smuzhiyun 		printk(UM_KERN_ERR "is_umdir_used - remove_files_and_dir "
206*4882a593Smuzhiyun 		       "failed with err = %d\n", ret);
207*4882a593Smuzhiyun 	}
208*4882a593Smuzhiyun 	return ret;
209*4882a593Smuzhiyun }
210*4882a593Smuzhiyun 
create_pid_file(void)211*4882a593Smuzhiyun static void __init create_pid_file(void)
212*4882a593Smuzhiyun {
213*4882a593Smuzhiyun 	char pid[sizeof("nnnnnnnnn")], *file;
214*4882a593Smuzhiyun 	int fd, n;
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun 	n = strlen(uml_dir) + UMID_LEN + sizeof("/pid");
217*4882a593Smuzhiyun 	file = malloc(n);
218*4882a593Smuzhiyun 	if (!file)
219*4882a593Smuzhiyun 		return;
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun 	if (umid_file_name("pid", file, n))
222*4882a593Smuzhiyun 		goto out;
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun 	fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0644);
225*4882a593Smuzhiyun 	if (fd < 0) {
226*4882a593Smuzhiyun 		printk(UM_KERN_ERR "Open of machine pid file \"%s\" failed: "
227*4882a593Smuzhiyun 		       "%s\n", file, strerror(errno));
228*4882a593Smuzhiyun 		goto out;
229*4882a593Smuzhiyun 	}
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun 	snprintf(pid, sizeof(pid), "%d\n", getpid());
232*4882a593Smuzhiyun 	n = write(fd, pid, strlen(pid));
233*4882a593Smuzhiyun 	if (n != strlen(pid))
234*4882a593Smuzhiyun 		printk(UM_KERN_ERR "Write of pid file failed - err = %d\n",
235*4882a593Smuzhiyun 		       errno);
236*4882a593Smuzhiyun 
237*4882a593Smuzhiyun 	close(fd);
238*4882a593Smuzhiyun out:
239*4882a593Smuzhiyun 	free(file);
240*4882a593Smuzhiyun }
241*4882a593Smuzhiyun 
set_umid(char * name)242*4882a593Smuzhiyun int __init set_umid(char *name)
243*4882a593Smuzhiyun {
244*4882a593Smuzhiyun 	if (strlen(name) > UMID_LEN - 1)
245*4882a593Smuzhiyun 		return -E2BIG;
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun 	strlcpy(umid, name, sizeof(umid));
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun 	return 0;
250*4882a593Smuzhiyun }
251*4882a593Smuzhiyun 
252*4882a593Smuzhiyun /* Changed in make_umid, which is called during early boot */
253*4882a593Smuzhiyun static int umid_setup = 0;
254*4882a593Smuzhiyun 
make_umid(void)255*4882a593Smuzhiyun static int __init make_umid(void)
256*4882a593Smuzhiyun {
257*4882a593Smuzhiyun 	int fd, err;
258*4882a593Smuzhiyun 	char tmp[256];
259*4882a593Smuzhiyun 
260*4882a593Smuzhiyun 	if (umid_setup)
261*4882a593Smuzhiyun 		return 0;
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun 	make_uml_dir();
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun 	if (*umid == '\0') {
266*4882a593Smuzhiyun 		strlcpy(tmp, uml_dir, sizeof(tmp));
267*4882a593Smuzhiyun 		strlcat(tmp, "XXXXXX", sizeof(tmp));
268*4882a593Smuzhiyun 		fd = mkstemp(tmp);
269*4882a593Smuzhiyun 		if (fd < 0) {
270*4882a593Smuzhiyun 			printk(UM_KERN_ERR "make_umid - mkstemp(%s) failed: "
271*4882a593Smuzhiyun 			       "%s\n", tmp, strerror(errno));
272*4882a593Smuzhiyun 			err = -errno;
273*4882a593Smuzhiyun 			goto err;
274*4882a593Smuzhiyun 		}
275*4882a593Smuzhiyun 
276*4882a593Smuzhiyun 		close(fd);
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun 		set_umid(&tmp[strlen(uml_dir)]);
279*4882a593Smuzhiyun 
280*4882a593Smuzhiyun 		/*
281*4882a593Smuzhiyun 		 * There's a nice tiny little race between this unlink and
282*4882a593Smuzhiyun 		 * the mkdir below.  It'd be nice if there were a mkstemp
283*4882a593Smuzhiyun 		 * for directories.
284*4882a593Smuzhiyun 		 */
285*4882a593Smuzhiyun 		if (unlink(tmp)) {
286*4882a593Smuzhiyun 			err = -errno;
287*4882a593Smuzhiyun 			goto err;
288*4882a593Smuzhiyun 		}
289*4882a593Smuzhiyun 	}
290*4882a593Smuzhiyun 
291*4882a593Smuzhiyun 	snprintf(tmp, sizeof(tmp), "%s%s", uml_dir, umid);
292*4882a593Smuzhiyun 	err = mkdir(tmp, 0777);
293*4882a593Smuzhiyun 	if (err < 0) {
294*4882a593Smuzhiyun 		err = -errno;
295*4882a593Smuzhiyun 		if (err != -EEXIST)
296*4882a593Smuzhiyun 			goto err;
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun 		if (umdir_take_if_dead(tmp) < 0)
299*4882a593Smuzhiyun 			goto err;
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun 		err = mkdir(tmp, 0777);
302*4882a593Smuzhiyun 	}
303*4882a593Smuzhiyun 	if (err) {
304*4882a593Smuzhiyun 		err = -errno;
305*4882a593Smuzhiyun 		printk(UM_KERN_ERR "Failed to create '%s' - err = %d\n", umid,
306*4882a593Smuzhiyun 		       errno);
307*4882a593Smuzhiyun 		goto err;
308*4882a593Smuzhiyun 	}
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun 	umid_setup = 1;
311*4882a593Smuzhiyun 
312*4882a593Smuzhiyun 	create_pid_file();
313*4882a593Smuzhiyun 
314*4882a593Smuzhiyun 	err = 0;
315*4882a593Smuzhiyun  err:
316*4882a593Smuzhiyun 	return err;
317*4882a593Smuzhiyun }
318*4882a593Smuzhiyun 
make_umid_init(void)319*4882a593Smuzhiyun static int __init make_umid_init(void)
320*4882a593Smuzhiyun {
321*4882a593Smuzhiyun 	if (!make_umid())
322*4882a593Smuzhiyun 		return 0;
323*4882a593Smuzhiyun 
324*4882a593Smuzhiyun 	/*
325*4882a593Smuzhiyun 	 * If initializing with the given umid failed, then try again with
326*4882a593Smuzhiyun 	 * a random one.
327*4882a593Smuzhiyun 	 */
328*4882a593Smuzhiyun 	printk(UM_KERN_ERR "Failed to initialize umid \"%s\", trying with a "
329*4882a593Smuzhiyun 	       "random umid\n", umid);
330*4882a593Smuzhiyun 	*umid = '\0';
331*4882a593Smuzhiyun 	make_umid();
332*4882a593Smuzhiyun 
333*4882a593Smuzhiyun 	return 0;
334*4882a593Smuzhiyun }
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun __initcall(make_umid_init);
337*4882a593Smuzhiyun 
umid_file_name(char * name,char * buf,int len)338*4882a593Smuzhiyun int __init umid_file_name(char *name, char *buf, int len)
339*4882a593Smuzhiyun {
340*4882a593Smuzhiyun 	int n, err;
341*4882a593Smuzhiyun 
342*4882a593Smuzhiyun 	err = make_umid();
343*4882a593Smuzhiyun 	if (err)
344*4882a593Smuzhiyun 		return err;
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun 	n = snprintf(buf, len, "%s%s/%s", uml_dir, umid, name);
347*4882a593Smuzhiyun 	if (n >= len) {
348*4882a593Smuzhiyun 		printk(UM_KERN_ERR "umid_file_name : buffer too short\n");
349*4882a593Smuzhiyun 		return -E2BIG;
350*4882a593Smuzhiyun 	}
351*4882a593Smuzhiyun 
352*4882a593Smuzhiyun 	return 0;
353*4882a593Smuzhiyun }
354*4882a593Smuzhiyun 
get_umid(void)355*4882a593Smuzhiyun char *get_umid(void)
356*4882a593Smuzhiyun {
357*4882a593Smuzhiyun 	return umid;
358*4882a593Smuzhiyun }
359*4882a593Smuzhiyun 
set_uml_dir(char * name,int * add)360*4882a593Smuzhiyun static int __init set_uml_dir(char *name, int *add)
361*4882a593Smuzhiyun {
362*4882a593Smuzhiyun 	if (*name == '\0') {
363*4882a593Smuzhiyun 		os_warn("uml_dir can't be an empty string\n");
364*4882a593Smuzhiyun 		return 0;
365*4882a593Smuzhiyun 	}
366*4882a593Smuzhiyun 
367*4882a593Smuzhiyun 	if (name[strlen(name) - 1] == '/') {
368*4882a593Smuzhiyun 		uml_dir = name;
369*4882a593Smuzhiyun 		return 0;
370*4882a593Smuzhiyun 	}
371*4882a593Smuzhiyun 
372*4882a593Smuzhiyun 	uml_dir = malloc(strlen(name) + 2);
373*4882a593Smuzhiyun 	if (uml_dir == NULL) {
374*4882a593Smuzhiyun 		os_warn("Failed to malloc uml_dir - error = %d\n", errno);
375*4882a593Smuzhiyun 
376*4882a593Smuzhiyun 		/*
377*4882a593Smuzhiyun 		 * Return 0 here because do_initcalls doesn't look at
378*4882a593Smuzhiyun 		 * the return value.
379*4882a593Smuzhiyun 		 */
380*4882a593Smuzhiyun 		return 0;
381*4882a593Smuzhiyun 	}
382*4882a593Smuzhiyun 	sprintf(uml_dir, "%s/", name);
383*4882a593Smuzhiyun 
384*4882a593Smuzhiyun 	return 0;
385*4882a593Smuzhiyun }
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun __uml_setup("uml_dir=", set_uml_dir,
388*4882a593Smuzhiyun "uml_dir=<directory>\n"
389*4882a593Smuzhiyun "    The location to place the pid and umid files.\n\n"
390*4882a593Smuzhiyun );
391*4882a593Smuzhiyun 
remove_umid_dir(void)392*4882a593Smuzhiyun static void remove_umid_dir(void)
393*4882a593Smuzhiyun {
394*4882a593Smuzhiyun 	char *dir, err;
395*4882a593Smuzhiyun 
396*4882a593Smuzhiyun 	dir = malloc(strlen(uml_dir) + UMID_LEN + 1);
397*4882a593Smuzhiyun 	if (!dir)
398*4882a593Smuzhiyun 		return;
399*4882a593Smuzhiyun 
400*4882a593Smuzhiyun 	sprintf(dir, "%s%s", uml_dir, umid);
401*4882a593Smuzhiyun 	err = remove_files_and_dir(dir);
402*4882a593Smuzhiyun 	if (err)
403*4882a593Smuzhiyun 		os_warn("%s - remove_files_and_dir failed with err = %d\n",
404*4882a593Smuzhiyun 			__func__, err);
405*4882a593Smuzhiyun 
406*4882a593Smuzhiyun 	free(dir);
407*4882a593Smuzhiyun }
408*4882a593Smuzhiyun 
409*4882a593Smuzhiyun __uml_exitcall(remove_umid_dir);
410