Skip to content

Commit 6f6eb26

Browse files
author
git-core
committed
Move frequently used code snippet in get_command()
1 parent 4eb8017 commit 6f6eb26

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

activity.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ int send_intent(struct su_context *ctx, const char *socket_path, int allow, int
110110
data.writeInt32(VAL_STRING);
111111
data.writeString16(String16("desired_cmd"));
112112
data.writeInt32(VAL_STRING);
113-
if (ctx->to.command)
114-
data.writeString16(String16(ctx->to.command));
115-
else
116-
data.writeString16(String16(ctx->to.shell));
113+
data.writeString16(String16(get_command(&ctx->to)));
117114

118115
data.writeInt32(VAL_STRING);
119116
data.writeString16(String16("socket"));

db.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static int db_check(sqlite3 *db, struct su_context *ctx)
5252
sqlite3_snprintf(
5353
sizeof(sql), sql,
5454
"SELECT _id,name,allow FROM apps WHERE uid=%u AND exec_uid=%u AND exec_cmd='%q';",
55-
ctx->from.uid, ctx->to.uid, (ctx->to.command) ? ctx->to.command : ctx->to.shell
55+
ctx->from.uid, ctx->to.uid, get_command(&ctx->to)
5656
);
5757

5858
if (strlen(sql) >= sizeof(sql)-1)

su.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ do { \
217217
PLOGE("write(bin)");
218218
return -1;
219219
}
220-
cmd = (ctx->to.command) ? ctx->to.command : ctx->to.shell;
220+
cmd = get_command(&ctx->to);
221221
cmd_size = strlen(cmd) + 1;
222222
write_token(fd, cmd_size);
223223
len = write(fd, cmd, cmd_size);
@@ -262,7 +262,7 @@ static void usage(int status)
262262

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

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

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

su.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ extern int database_check(struct su_context *ctx);
7272

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

75+
static inline char *get_command(struct su_request *to)
76+
{
77+
return (to->command) ? to->command : to->shell;
78+
}
79+
7580
#if 0
7681
#undef LOGE
7782
#define LOGE(fmt,args...) fprintf(stderr, fmt , ## args )

0 commit comments

Comments
 (0)