@@ -22,15 +22,7 @@ unsigned long long jbrand() {
2222}
2323
2424static void __attribute__((__constructor__ )) _jbroot_init ()
25- {
26- if (access ("/var/.jbroottest" , F_OK )== 0 || getenv ("JBROOTTEST" ))
27- {
28- setenv ("JBRAND" , "1234567890ABCDEF" , 1 );
29- //setenv("JBROOT", "/private/var/.jbroot-1234567890ABCDEF", 1);
30- // use /var/ instead of /private/var/ because stringByResolvingSymlinksInPath won't resolve /var/
31- setenv ("JBROOT" , "/var/.jbroot-1234567890ABCDEF" , 1 );
32- }
33-
25+ {
3426 JBRAND = getenv ("JBRAND" );
3527 JBROOT = getenv ("JBROOT" );
3628
@@ -77,11 +69,14 @@ static void __attribute__((__constructor__)) _jbroot_init()
7769//free after use
7870static const char * __private_jbrootat_alloc (int fd , const char * path )
7971{
72+ int olderr = errno ;
73+
8074 char atdir [PATH_MAX ]= {0 };
8175 fd == AT_FDCWD ? (long )getcwd (atdir ,sizeof (atdir )) : fcntl (fd , F_GETPATH , atdir , sizeof (atdir ));
82- LOG (" **jbrootat_alloc (%d)%s %s\n" , fd , atdir , path );
76+ JBPATH_LOG (" **jbrootat_alloc (%d)%s %s\n" , fd , atdir , path );
8377
8478 if (!path || !* path ) {
79+ errno = olderr ;
8580 return NULL ;
8681 }
8782
@@ -195,8 +190,9 @@ static const char* __private_jbrootat_alloc(int fd, const char* path)
195190 resolved [resolved_len - 1 ] = '\0' ;
196191
197192
198- LOG ("*resolved:%ld %s\n" , resolved_len , resolved );
193+ JBPATH_LOG ("*resolved:%ld %s\n" , resolved_len , resolved );
199194
195+ errno = olderr ;
200196 return strdup (resolved );
201197}
202198
@@ -214,21 +210,20 @@ const char* jbrootat_alloc(int fd, const char* path)
214210 if (fixedpath [0 ] != '/' ) return fixedpath ;
215211
216212 //its necessary for symlink /rootfs/xxx -> /rootfs/yyy
217- if (strlen (fixedpath )>=(sizeof ("/rootfs" )- 1 )
218- && strncmp (fixedpath , "/rootfs" , sizeof ("/rootfs" )- 1 )== 0 )
213+ if (strlen (fixedpath )>=(sizeof ("/" ROOTFS_NAME )- 1 )
214+ && strncmp (fixedpath , "/" ROOTFS_NAME , sizeof ("/" ROOTFS_NAME )- 1 )== 0 )
219215 {
216+ // char atdir[PATH_MAX]={0};
217+ // fd==AT_FDCWD ? (long)getcwd(atdir,sizeof(atdir)) : fcntl(fd, F_GETPATH, atdir, sizeof(atdir));
218+ // printf(" **rootfs--> (%d)%s\n\t%s : %s\n", fd, atdir, path, fixedpath);
220219
221- // char atdir[PATH_MAX]={0};
222- // fd==AT_FDCWD ? (long)getcwd(atdir,sizeof(atdir)) : fcntl(fd, F_GETPATH, atdir, sizeof(atdir));
223- // printf(" **rootfs--> (%d)%s\n\t%s\n\t%s\n", fd, atdir, path, fixedpath);
224-
225- if (fixedpath [sizeof ("/rootfs" )- 1 ]== '/' ) {
226- char * newpath = strdup (& fixedpath [sizeof ("/rootfs" )- 1 ]);
220+ if (fixedpath [sizeof ("/" ROOTFS_NAME )- 1 ]== '/' ) {
221+ char * newpath = strdup (& fixedpath [sizeof ("/" ROOTFS_NAME )- 1 ]);
227222 free ((void * )fixedpath );
228223 return newpath ;
229224 }
230- //break find / ???
231- if (fixedpath [sizeof ("/rootfs" )- 1 ]== '\0' ) {
225+ //break find / and cd rootfs;realpath . ??? caused by lstat(jbroot("/rootfs")) in vroot module
226+ if (fixedpath [sizeof ("/" ROOTFS_NAME )- 1 ]== '\0' ) {
232227 free ((void * )fixedpath );
233228 return strdup ("/" );
234229 }
@@ -254,9 +249,12 @@ const char* jbroot_alloc(const char* path)
254249//free after use
255250static const char * __private_rootfs_alloc (const char * path )
256251{
257- LOG (" **rootfs_alloc %s\n" , path );
252+ int olderr = errno ;
253+
254+ JBPATH_LOG (" **rootfs_alloc %s\n" , path );
258255
259256 if (!path || !* path ) {
257+ errno = olderr ;
260258 return NULL ;
261259 }
262260
@@ -352,15 +350,16 @@ static const char* __private_rootfs_alloc(const char* path)
352350 char * retval = NULL ;
353351 if (jbroot_based == 0 && path [0 ] == '/' ) { //revert a path out of jbroot?
354352 assert (resolved [0 ] == '/' );
355- retval = malloc (sizeof (ROOTFS_PREFIX )- 1 + strlen (resolved ) + 1 );
356- strcpy (retval , ROOTFS_PREFIX );//just add ROOTFS_PREFIX prefix
353+ retval = malloc (sizeof ("/" ROOTFS_NAME )- 1 + strlen (resolved ) + 1 );
354+ strcpy (retval , "/" ROOTFS_NAME );//just add rootfs prefix
357355 strcat (retval , resolved );
358356 } else {
359357 retval = strdup (resolved );
360358 }
361359
362- LOG ("*resolved:%ld %s\n" , resolved_len , retval );
360+ JBPATH_LOG ("*resolved:%ld %s\n" , resolved_len , retval );
363361
362+ errno = olderr ;
364363 return retval ;
365364}
366365
0 commit comments