Skip to content

Commit a386d38

Browse files
gianlucaborelloluca3m
authored andcommitted
Remove cwd parsing from the driver because the function became sleepable in 4.8 (torvalds/linux@47be618).
When forking a new process, inherit the cwd from the parent.
1 parent f0857b4 commit a386d38

File tree

5 files changed

+17
-79
lines changed

5 files changed

+17
-79
lines changed

driver/ppm_events.c

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -705,61 +705,6 @@ int val_to_ring(struct event_filler_arguments *args, uint64_t val, u16 val_len,
705705
return PPM_SUCCESS;
706706
}
707707

708-
/*
709-
* Get the current working directory for the current process.
710-
* Returns the pointer to the string, which is NOT going to be at the beginning
711-
* of buf.
712-
* Buf must be at least 1 page in size.
713-
*/
714-
#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 20)
715-
char *npm_getcwd(char *buf, unsigned long bufsize)
716-
{
717-
struct path pwd;
718-
char *res;
719-
720-
ASSERT(bufsize >= PAGE_SIZE - 1);
721-
722-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36) || defined CONFIG_VE
723-
get_fs_pwd(current->fs, &pwd);
724-
#else
725-
read_lock(&current->fs->lock);
726-
pwd = current->fs->pwd;
727-
path_get(&pwd);
728-
read_unlock(&current->fs->lock);
729-
#endif
730-
731-
res = d_path(&pwd, buf, bufsize);
732-
733-
if (IS_ERR(res))
734-
res = NULL;
735-
736-
path_put(&pwd);
737-
738-
return res;
739-
}
740-
#else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 20) */
741-
char *npm_getcwd(char *buf, unsigned long bufsize)
742-
{
743-
struct dentry *dentry;
744-
struct vfsmount *mnt;
745-
char *res;
746-
747-
ASSERT(bufsize >= PAGE_SIZE - 1);
748-
749-
read_lock(&current->fs->lock);
750-
mnt = mntget(current->fs->pwdmnt);
751-
dentry = dget(current->fs->pwd);
752-
read_unlock(&current->fs->lock);
753-
754-
res = d_path(dentry, mnt, buf, bufsize);
755-
756-
if (IS_ERR(res))
757-
res = NULL;
758-
759-
return res;
760-
}
761-
#endif
762-
763708
static inline u8 socket_family_to_scap(u8 family)
764709
{
765710
if (family == AF_INET)

driver/ppm_events.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ extern const struct ppm_event_entry g_ppm_events[];
129129
int32_t dpi_lookahead_init(void);
130130
int32_t f_sys_autofill(struct event_filler_arguments *args, const struct ppm_event_entry *evinfo);
131131
int32_t val_to_ring(struct event_filler_arguments *args, u64 val, u16 val_len, bool fromuser, u8 dyn_idx);
132-
char *npm_getcwd(char *buf, unsigned long bufsize);
133132
u16 pack_addr(struct sockaddr *usrsockaddr, int ulen, char *targetbuf, u16 targetbufsize);
134133
u16 fd_to_socktuple(int fd, struct sockaddr *usrsockaddr, int ulen, bool use_userdata, bool is_inbound, char *targetbuf, u16 targetbufsize);
135134
int addr_to_kernel(void __user *uaddr, int ulen, struct sockaddr *kaddr);

driver/ppm_fillers.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ static int f_proc_startupdate(struct event_filler_arguments *args)
10061006
struct mm_struct *mm = current->mm;
10071007
int64_t retval;
10081008
int ptid;
1009-
char *spwd;
1009+
char *spwd = "";
10101010
long total_vm = 0;
10111011
long total_rss = 0;
10121012
long swap = 0;
@@ -1149,14 +1149,9 @@ static int f_proc_startupdate(struct event_filler_arguments *args)
11491149
return res;
11501150

11511151
/*
1152-
* cwd
1152+
* cwd, pushed empty to avoid breaking compatibility
1153+
* with the older event format
11531154
*/
1154-
spwd = npm_getcwd(args->str_storage, STR_STORAGE_SIZE - 1);
1155-
if (spwd == NULL)
1156-
spwd = "";
1157-
1158-
args->str_storage[STR_STORAGE_SIZE - 1] = '\0';
1159-
11601155
res = val_to_ring(args, (uint64_t)(long)spwd, 0, false, 0);
11611156
if (unlikely(res != PPM_SUCCESS))
11621157
return res;

test/sysdig_trace_regression.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ $BASEDIR/sysdig_batch_parser.sh $SYSDIG $CHISELS "-cps" $TRACEDIR $RESULTDIR/ps
104104
$BASEDIR/sysdig_batch_parser.sh $SYSDIG $CHISELS "-j -n 10000" $TRACEDIR $RESULTDIR/fd_fields_json $BASELINEDIR/fd_fields_json || ret=1
105105
# Sessions
106106
$BASEDIR/sysdig_batch_parser.sh $SYSDIG $CHISELS "-p '*%evt.num %evt.outputtime %evt.cpu %proc.name (%thread.tid) %evt.dir %evt.type %evt.info sid=%proc.sid sname=%proc.sname'" $TRACEDIR $RESULTDIR/sessions $BASELINEDIR/sessions || ret=1
107+
# Cwd
108+
$BASEDIR/sysdig_batch_parser.sh $SYSDIG $CHISELS "-pc -p\"*%evt.num %evt.outputtime %evt.cpu %container.name (%container.id) %proc.name (%thread.tid:%thread.vtid) %evt.dir %evt.type %evt.info %proc.cwd\"" $TRACEDIR $RESULTDIR/cwd $BASELINEDIR/cwd || ret=1
107109

108110
rm -rf "${TMPBASE}"
109111
exit $ret

userspace/libsinsp/parsers.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,22 +1221,27 @@ void sinsp_parser::parse_clone_exit(sinsp_evt *evt)
12211221
tinfo.m_pid = childtid;
12221222
}
12231223

1224-
//
1225-
// Copy the fd list
1226-
// XXX this is a gross oversimplification that will need to be fixed.
1227-
// What we do is: if the child is NOT a thread, we copy all the parent fds.
1228-
// The right thing to do is looking at PPM_CL_CLONE_FILES, but there are
1229-
// syscalls like open and pipe2 that can override PPM_CL_CLONE_FILES with the O_CLOEXEC flag
1230-
//
12311224
if(!(tinfo.m_flags & PPM_CL_CLONE_THREAD))
12321225
{
1226+
//
1227+
// Copy the fd list
1228+
// XXX this is a gross oversimplification that will need to be fixed.
1229+
// What we do is: if the child is NOT a thread, we copy all the parent fds.
1230+
// The right thing to do is looking at PPM_CL_CLONE_FILES, but there are
1231+
// syscalls like open and pipe2 that can override PPM_CL_CLONE_FILES with the O_CLOEXEC flag
1232+
//
12331233
tinfo.m_fdtable = *(ptinfo->get_fd_table());
12341234

12351235
//
12361236
// It's important to reset the cache of the child thread, to prevent it from
12371237
// referring to an element in the parent's table.
12381238
//
12391239
tinfo.m_fdtable.reset_cache();
1240+
1241+
//
1242+
// Not a thread, copy cwd
1243+
//
1244+
tinfo.m_cwd = ptinfo->m_cwd;
12401245
}
12411246
//if((tinfo.m_flags & (PPM_CL_CLONE_FILES)))
12421247
//{
@@ -1277,10 +1282,6 @@ void sinsp_parser::parse_clone_exit(sinsp_evt *evt)
12771282
parinfo = evt->get_param(2);
12781283
tinfo.set_args(parinfo->m_val, parinfo->m_len);
12791284

1280-
// Copy the working directory
1281-
parinfo = evt->get_param(6);
1282-
tinfo.set_cwd(parinfo->m_val, parinfo->m_len);
1283-
12841285
// Copy the fdlimit
12851286
parinfo = evt->get_param(7);
12861287
ASSERT(parinfo->m_len == sizeof(int64_t));
@@ -1517,10 +1518,6 @@ void sinsp_parser::parse_execve_exit(sinsp_evt *evt)
15171518
ASSERT(parinfo->m_len == sizeof(uint64_t));
15181519
evt->m_tinfo->m_pid = *(uint64_t *)parinfo->m_val;
15191520

1520-
// Get the working directory
1521-
parinfo = evt->get_param(6);
1522-
evt->m_tinfo->set_cwd(parinfo->m_val, parinfo->m_len);
1523-
15241521
// Get the fdlimit
15251522
parinfo = evt->get_param(7);
15261523
ASSERT(parinfo->m_len == sizeof(int64_t));

0 commit comments

Comments
 (0)