Skip to content

Commit

Permalink
make cdba user variable global
Browse files Browse the repository at this point in the history
Allow it to be accessed outside cdba-server.c

Signed-off-by: Caleb Connolly <[email protected]>
  • Loading branch information
calebccff committed Oct 17, 2024
1 parent 2f3e661 commit de2f592
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
18 changes: 8 additions & 10 deletions cdba-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include "list.h"
#include "watch.h"

static const char *username;

struct device *selected_device;

static void fastboot_opened(struct fastboot *fb, void *data)
Expand Down Expand Up @@ -55,7 +53,7 @@ static struct fastboot_ops fastboot_ops = {

static void msg_select_board(const void *param)
{
selected_device = device_open(param, username);
selected_device = device_open(param, cdba_user);
if (!selected_device) {
fprintf(stderr, "failed to open %s\n", (const char *)param);
watch_quit();
Expand Down Expand Up @@ -177,10 +175,10 @@ static int handle_stdin(int fd, void *buf)
device_send_break(selected_device);
break;
case MSG_LIST_DEVICES:
device_list_devices(username);
device_list_devices(cdba_user);
break;
case MSG_BOARD_INFO:
device_info(username, msg->data, msg->len);
device_info(cdba_user, msg->data, msg->len);
break;
case MSG_FASTBOOT_CONTINUE:
msg_fastboot_continue();
Expand Down Expand Up @@ -215,11 +213,11 @@ int main(int argc, char **argv)

fprintf(stderr, "Starting cdba server\n");

username = getenv("CDBA_USER");
if (!username)
username = getenv("USER");
if (!username)
username = "nobody";
cdba_user = getenv("CDBA_USER");
if (!cdba_user)
cdba_user = getenv("USER");
if (!cdba_user)
cdba_user = "nobody";

openlog("cdba-server", LOG_PID, LOG_DAEMON);
atexit(atexit_handler);
Expand Down
2 changes: 2 additions & 0 deletions cdba-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "cdba.h"

extern const char *cdba_user;

void cdba_send_buf(int type, size_t len, const void *buf);
#define cdba_send(type) cdba_send_buf(type, 0, NULL)

Expand Down
2 changes: 2 additions & 0 deletions device.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "status-cmd.h"
#include "watch.h"

const char *cdba_user;

#define ARRAY_SIZE(x) ((sizeof(x)/sizeof((x)[0])))

#define device_has_control(_dev, _op) \
Expand Down

0 comments on commit de2f592

Please sign in to comment.