Skip to content

Commit

Permalink
[debug] Use wrapper for popen() calls. Fixes MER#1774
Browse files Browse the repository at this point in the history
Calling popen() function indicates that usb-moded mainloop is blocked until
the subprocess finishes and it is difficult to tell whether such things
occur or not.

When in verbose mode, log subprocesses executed via popen().

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Mar 24, 2017
1 parent c2d824d commit 5005510
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/usb_moded-modesetting.c
Expand Up @@ -363,7 +363,7 @@ static void report_mass_storage_blocker(const char *mountpoint, int try)

lsof_command = g_strconcat("lsof ", mountpoint, NULL);

if( (stream = popen(lsof_command, "r")) )
if( (stream = usb_moded_popen(lsof_command, "r")) )
{
char *text = 0;
size_t size = 0;
Expand Down
12 changes: 12 additions & 0 deletions src/usb_moded.c
Expand Up @@ -1147,6 +1147,18 @@ usb_moded_system_(const char *file, int line, const char *func,
return rc;
}

/** Wrapper to give visibility subprocesses usb-moded is invoking via popen()
*/
FILE *
usb_moded_popen_(const char *file, int line, const char *func,
const char *command, const char *type)
{
log_debug("EXEC %s; from %s:%d: %s()",
command, file, line, func);

return popen(command, type);
}

/** Wrapper to give visibility to blocking sleeps usb-moded is making
*/
void
Expand Down
3 changes: 3 additions & 0 deletions src/usb_moded.h
Expand Up @@ -99,6 +99,9 @@ void usb_moded_stop(int exitcode);
int usb_moded_system_(const char *file, int line, const char *func, const char *command);
#define usb_moded_system(command) usb_moded_system_(__FILE__,__LINE__,__FUNCTION__,(command))

FILE *usb_moded_popen_(const char *file, int line, const char *func, const char *command, const char *type);
#define usb_moded_popen(command, type) usb_moded_popen_(__FILE__,__LINE__,__FUNCTION__,(command),(type))

void usb_moded_usleep_(const char *file, int line, const char *func, useconds_t usec);
#define usb_moded_usleep(usec) usb_moded_usleep_(__FILE__,__LINE__,__FUNCTION__,(usec))
#define usb_moded_msleep(msec) usb_moded_usleep_(__FILE__,__LINE__,__FUNCTION__,(msec)*1000)
Expand Down

0 comments on commit 5005510

Please sign in to comment.