@@ -189,15 +189,25 @@ static int hyperfs_open(const char *path, struct fuse_file_info *fi) {
189189 }
190190}
191191
192+ // Return whether a path is /proc/self or /proc/PID
193+ static bool is_proc_pid_path (const char * path )
194+ {
195+ int pid , len ;
196+ bool is_proc_self = !strcmp (path , "/proc/self" );
197+ bool is_proc_pid = sscanf (path , "/proc/%d%n" , & pid , & len ) == 1 && len == strlen (path );
198+ return is_proc_self || is_proc_pid ;
199+ }
200+
192201static int hyperfs_getattr (const char * path , struct stat * st ,
193202 struct fuse_file_info * fi ) {
194203 trace ("%s(%s, st=%p, fi=%p)" , __func__ , path , st , fi );
195204
205+ memset (st , 0 , sizeof (struct stat ));
206+ st -> st_nlink = !strcmp (path , "/" ) ? 2 : 1 ;
207+
196208 int mode = lookup_mode (path );
197209
198210 if (mode >= 0 ) {
199- memset (st , 0 , sizeof (struct stat ));
200- st -> st_nlink = !strcmp (path , "/" ) ? 2 : 1 ;
201211 st -> st_mode = mode ;
202212 if (mode == DEV_MODE ) {
203213 hyp_file_op ((struct hyperfs_data ){
@@ -207,6 +217,9 @@ static int hyperfs_getattr(const char *path, struct stat *st,
207217 });
208218 }
209219 return 0 ;
220+ } else if (is_proc_pid_path (path )) {
221+ st -> st_mode = S_IFLNK | 0777 ;
222+ return 0 ;
210223 } else {
211224 return xmp_getattr (path , st , fi );
212225 }
@@ -303,8 +316,8 @@ static int hyperfs_readlink(const char *path, char *buf, size_t size) {
303316 trace ("%s(%s, buf=%s, size=%zu)" , __func__ , path , buf , size );
304317 if (exists (path )) {
305318 return - EINVAL ;
306- } else if (! strcmp (path , "/proc/self" )) {
307- snprintf (buf , size , "%s/proc/self " , options .passthrough_path );
319+ } else if (is_proc_pid_path (path )) {
320+ snprintf (buf , size , "%s%s " , options .passthrough_path , path );
308321 return 0 ;
309322 } else {
310323 return xmp_readlink (path , buf , size );
0 commit comments