Skip to content

Commit

Permalink
Move frequently used code snippet in get_command()
Browse files Browse the repository at this point in the history
  • Loading branch information
git-core committed Jan 29, 2012
1 parent 4eb8017 commit 6f6eb26
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
5 changes: 1 addition & 4 deletions activity.cpp
Expand Up @@ -110,10 +110,7 @@ int send_intent(struct su_context *ctx, const char *socket_path, int allow, int
data.writeInt32(VAL_STRING);
data.writeString16(String16("desired_cmd"));
data.writeInt32(VAL_STRING);
if (ctx->to.command)
data.writeString16(String16(ctx->to.command));
else
data.writeString16(String16(ctx->to.shell));
data.writeString16(String16(get_command(&ctx->to)));

data.writeInt32(VAL_STRING);
data.writeString16(String16("socket"));
Expand Down
2 changes: 1 addition & 1 deletion db.c
Expand Up @@ -52,7 +52,7 @@ static int db_check(sqlite3 *db, struct su_context *ctx)
sqlite3_snprintf(
sizeof(sql), sql,
"SELECT _id,name,allow FROM apps WHERE uid=%u AND exec_uid=%u AND exec_cmd='%q';",
ctx->from.uid, ctx->to.uid, (ctx->to.command) ? ctx->to.command : ctx->to.shell
ctx->from.uid, ctx->to.uid, get_command(&ctx->to)
);

if (strlen(sql) >= sizeof(sql)-1)
Expand Down
6 changes: 3 additions & 3 deletions su.c
Expand Up @@ -217,7 +217,7 @@ do { \
PLOGE("write(bin)");
return -1;
}
cmd = (ctx->to.command) ? ctx->to.command : ctx->to.shell;
cmd = get_command(&ctx->to);
cmd_size = strlen(cmd) + 1;
write_token(fd, cmd_size);
len = write(fd, cmd, cmd_size);
Expand Down Expand Up @@ -262,7 +262,7 @@ static void usage(int status)

static void deny(struct su_context *ctx)
{
char *cmd = (ctx->to.command) ? ctx->to.command : ctx->to.shell;
char *cmd = get_command(&ctx->to);

send_intent(ctx, "", 0, 1);
LOGW("request rejected (%u->%u %s)", ctx->from.uid, ctx->to.uid, cmd);
Expand Down Expand Up @@ -306,7 +306,7 @@ static void allow(struct su_context *ctx)

LOGD("%u %s executing %u %s using shell %s : %s%s%s%s%s%s%s%s%s%s%s%s%s%s",
ctx->from.uid, ctx->from.bin,
ctx->to.uid, (ctx->to.command) ? ctx->to.command : ctx->to.shell, ctx->to.shell,
ctx->to.uid, get_command(&ctx->to), ctx->to.shell,
arg0, PARG(0), PARG(1), PARG(2), PARG(3), PARG(4), PARG(5),
(ctx->to.optind + 6 < ctx->to.argc) ? " ..." : "");

Expand Down
5 changes: 5 additions & 0 deletions su.h
Expand Up @@ -72,6 +72,11 @@ extern int database_check(struct su_context *ctx);

extern int send_intent(struct su_context *ctx, const char *socket_path, int allow, int type);

static inline char *get_command(struct su_request *to)
{
return (to->command) ? to->command : to->shell;
}

#if 0
#undef LOGE
#define LOGE(fmt,args...) fprintf(stderr, fmt , ## args )
Expand Down

0 comments on commit 6f6eb26

Please sign in to comment.