* limitations under the License.
*/
-#define TRACE_TAG TRACE_SDB
+//#define TRACE_TAG TRACE_SDB
+#define LOG_TAG "SDBD_TRACE_SDB"
#include <stdio.h>
#include <stdlib.h>
#include "sdktools.h"
#include "plugin.h"
#include "sdbd_plugin.h"
+#include "sdb_systemd.h"
#ifdef SUPPORT_ENCRYPT
#include "plugin_encrypt.h"
#endif
#include <linux/prctl.h>
-#define SDB_PIDPATH "/tmp/.sdbd.pid"
#include <system_info.h>
#include <vconf.h>
#include <glib.h>
#define SDB_LOGCONF_PATH "/tmp/.sdbdlog.conf"
int HOST = 0;
+int exit_cleanup_required = 0;
// sdk user
uid_t g_sdk_user_id;
};
#define SDB_DEFAULT_GROUPS_CNT ((sizeof(g_default_groups)/sizeof(g_default_groups[0]))-1)
+#define BUF_SIZE 4096
int is_init_sdk_userinfo = 0;
int is_pwlocked = 0; // 0 if unlocked, 1 otherwise
+int recovery_mode = 0;
+
SdbdCommandlineArgs sdbd_commandline_args;
static int is_support_usbproto();
return 0;
}
+int is_netcoredbg_supported(void) {
+
+ FILE *fp = fopen(NETCOREDBG_LOCATION, "r");
+ if (fp) {
+ size_t len;
+ ssize_t num;
+ char *line = NULL;
+
+ while ((num = getline(&line, &len, fp)) != -1) {
+ if (strstr(line, "NETCOREDBG") != NULL) {
+ snprintf(g_capabilities.netcoredbg_support, sizeof(g_capabilities.netcoredbg_support),
+ "%s", ENABLED);
+ free(line);
+ fclose(fp);
+ return 1;
+ }
+ free(line);
+ line = NULL;
+ }
+ fclose(fp);
+ }
+ return 0;
+}
+
+const char* get_platfrom_architecture(void) {
+ void* void_pointer;
+ D("void pointer size: %zu", sizeof(void_pointer));
+ // in 32 bit sizeof void* is 4 and in 64 bit its 8
+ if((int)(sizeof(void_pointer)) == 4)
+ return BIT32;
+ if((int)(sizeof(void_pointer)) == 8)
+ return BIT64;
+ return UNKNOWN;
+}
+
int is_container_enabled(void) {
bool value;
int ret;
ret = system_info_get_platform_bool("tizen.org/feature/container", &value);
if (ret != SYSTEM_INFO_ERROR_NONE) {
- D("failed to get container information: %d\n", errno);
+ E("failed to get container information: %d\n", errno);
return 0;
} else {
D("tizen container: %d\n", value);
}
}
-void handle_sig_term(int sig) {
-#ifdef SDB_PIDPATH
- if (access(SDB_PIDPATH, F_OK) == 0)
- sdb_unlink(SDB_PIDPATH);
-#endif
-}
static const char *sdb_device_banner = "device";
fd = unix_open(SDB_LOGCONF_PATH, O_RDONLY);
if (fd < 0) {
- D("failed to open '%s' file: %d\n", SDB_LOGCONF_PATH, errno);
+ E("failed to open '%s' file: %d\n", SDB_LOGCONF_PATH, errno);
return NULL;
}
if (end != NULL) {
strncpy(value, start, end - start);
} else {
- strncpy(value, start, sizeof(value));
+ strncpy(value, start, sizeof(value) - 1);
+ value[sizeof(value) - 1] = '\0';
}
} else {
sdb_close(fd);
static int is_enable_sdbd_log()
{
- return (!strncmp(g_capabilities.log_enable, PLUGIN_RET_ENABLED, strlen(PLUGIN_RET_ENABLED)));
+ return (!strncmp(g_capabilities.log_enable, PLUGIN_RET_ENABLED, strlen(PLUGIN_RET_ENABLED)+1));
}
int sdb_trace_mask;
apacket *get_apacket(void)
{
apacket *p = malloc(sizeof(apacket));
- if(p == 0) fatal("failed to allocate an apacket");
+ if(p == 0) {
+ // free only being done to resolve SVACE issue.
+ free(p) ;
+ fatal("failed to allocate an apacket");
+ }
memset(p, 0, sizeof(apacket) - MAX_PAYLOAD);
return p;
}
void put_apacket(apacket *p)
{
+ int result = access((const char *) p, F_OK);
+ if ((result == -1) && (errno == EFAULT)) {
+ E("Invalid apacket = [0x%p]", p);
+ fatal("Invalid apacket = [0x%p]", p);
+ }
if (p != NULL) {
free(p);
p = NULL;
void handle_online(void)
{
- D("sdb: online\n");
+ I("sdb: online\n");
}
void handle_offline(atransport *t)
{
- D("sdb: offline\n");
+ I("sdb: offline\n");
//Close the associated usb
run_transport_disconnects(t);
}
t->sessionID = sessionID;
if((retVal = security_init(t->sessionID, NULL)) == 1){ // 암호화 handshaking을 위한 init
if(security_parse_server_hello(t->sessionID, p) == 1){ // hello 메시지 파싱
- D("security_parse_server_hello success\n");
+ I("security_parse_server_hello success\n");
enc_p = get_apacket();
if(security_gen_client_hello(t->sessionID, enc_p) == 1){ // hello 메시지 생성
- D("security_gen_client_hello success\n");
+ I("security_gen_client_hello success\n");
enc_p->msg.command = A_ENCR;
enc_p->msg.arg0 = ENCR_SET_ON_REQ;
enc_p->msg.arg1 = p->msg.arg1;
send_packet(enc_p, t);
}
else { // hello 메시지 생성 실패
- D("security_gen_client_hello error\n");
+ E("security_gen_client_hello error\n");
send_encr_fail(p, t, ENCR_ON_FAIL); // 암호화 on 실패 메시지 전송
t->encryption = ENCR_OFF; // 암호화 모드는 off
security_deinit(t->sessionID);
}
}
else{ // hello 메시지 파싱 실패
- D("security_parse_server_hello error\n");
+ E("security_parse_server_hello error\n");
send_encr_fail(p, t, ENCR_ON_FAIL);
t->encryption = ENCR_OFF;
security_deinit(t->sessionID);
return -1;
}
} else { // init 실패
- D("security_init error\n");
+ E("security_init error\n");
send_encr_fail(p, t, ENCR_ON_FAIL);
t->encryption = ENCR_OFF;
if (retVal == 0)
if(security_parse_server_ack(t->sessionID, p) == 1){ // ack 메시지 파싱
enc_p = get_apacket();
if(security_gen_client_ack(t->sessionID, enc_p) == 1){ // ack 메시지 생성
- D("security_gen_client_ack success\n");
+ I("security_gen_client_ack success\n");
enc_p->msg.command = A_ENCR;
enc_p->msg.arg0 = ENCR_SET_ON_OK;
enc_p->msg.arg1 = p->msg.arg1;
send_packet(enc_p, t);
}
else { // ack 메시지 생성에 실패한 경우
- D("security_gen_client_ack error\n");
+ E("security_gen_client_ack error\n");
send_encr_fail(p, t, ENCR_ON_FAIL);
t->encryption = ENCR_OFF;
security_deinit(t->sessionID);
}
}
else { // ack 메시지 파싱에 실패한 경우
- D("security_parse_server_ack error\n");
+ E("security_parse_server_ack error\n");
send_encr_fail(p, t, ENCR_ON_FAIL);
t->encryption = ENCR_OFF;
security_deinit(t->sessionID);
send_packet(enc_p, t);
}
else { // 암호화 모드 off에 실패한 경우
- D("security_deinit error\n");
+ E("security_deinit error\n");
send_encr_fail(p, t, ENCR_OFF_FAIL); // 암호화 모드 off 실패 메시지 전송
return -1;
}
enc_p->msg.arg1 = p->msg.arg1;
if(t->encryption == ENCR_ON){ // 암호화 모드가 on인 경우
enc_p->msg.data_length = 13;
- strncpy((char*)enc_p->data, "encryption:on", enc_p->msg.data_length); // encryption:on 메시지 전송
+ strncpy((char*)enc_p->data, "encryption:on", enc_p->msg.data_length + 1); // encryption:on 메시지 전송
} else if(t->encryption == ENCR_OFF){ // 암호화 모드가 off인 경우
enc_p->msg.data_length = 14;
- strncpy((char*)enc_p->data, "encryption:off", enc_p->msg.data_length); // encryption:off 메시지 전송
+ strncpy((char*)enc_p->data, "encryption:off", enc_p->msg.data_length + 1); // encryption:off 메시지 전송
}
send_packet(enc_p, t);
}
else if (p->msg.arg0 == ENCR_ON_FAIL) // 암호화 모드를 on 하는 도중 실패한 경우 받는 메시지
{
t->encryption = ENCR_OFF; // 암호화 모드를 다시 off
- D("encryption on failed\n");
+ E("encryption on failed\n");
}
else if (p->msg.arg0 == ENCR_OFF_FAIL) // 암호화 모드를 off하는 도중 실패한 경우 받는 메시지
{
//t->encryption = ENCR_ON;
- D("encryption off failed\n");
+ E("encryption off failed\n");
}
//put_apacket(enc_p);
return 0;
static void send_ready(unsigned local, unsigned remote, atransport *t)
{
- D("Calling send_ready \n");
+ I("Calling send_ready \n");
apacket *p = get_apacket();
p->msg.command = A_OKAY;
p->msg.arg0 = local;
static void send_close(unsigned local, unsigned remote, atransport *t)
{
- D("Calling send_close \n");
+ I("Calling send_close \n");
apacket *p = get_apacket();
p->msg.command = A_CLSE;
p->msg.arg0 = local;
static void send_connect(atransport *t)
{
- D("Calling send_connect \n");
+ I("Calling send_connect \n");
apacket *cp = get_apacket();
cp->msg.command = A_CNXN;
cp->msg.arg0 = A_VERSION;
snprintf((char*) cp->data, sizeof cp->data, "%s::%s::%d", sdb_device_banner, device_name, status);
}
- D("CNXN data:%s\n", (char*)cp->data);
+ if (extcmd != NULL) {
+ char extbuf[BUF_SIZE] = {0,};
+ snprintf(extbuf, sizeof extbuf, "::%s", extcmd);
+ strncat((char*) cp->data, extbuf, sizeof(cp->data) - strlen((const char*)cp->data)- 1);
+ }
cp->msg.data_length = strlen((char*) cp->data) + 1;
+ D("CNXN data: %s\n", (char*)cp->data);
send_packet(cp, t);
}
void send_device_status()
{
- D("broadcast device status\n");
+ I("broadcast device status\n");
apacket* cp = get_apacket();
cp->msg.command = A_STAT;
cp->msg.arg0 = is_pwlocked;
int len = e-s-strlen(dest);
if (len >= str_size) {
- D("buffer size(%d) should be bigger than %d\n", str_size, len+1);
+ E("buffer size(%d) should be bigger than %d\n", str_size, len+1);
return -1;
}
char *value = NULL;
int r = system_info_get_platform_string("http://tizen.org/system/model_name", &value);
if (r != SYSTEM_INFO_ERROR_NONE) {
- D("fail to get system model:%d\n", errno);
+ E("fail to get system model:%d\n", errno);
return -1;
} else {
s_strncpy(str, value, str_size);
int fd = unix_open(PROC_CMDLINE_PATH, O_RDONLY);
if (fd < 0) {
- D("fail to read /proc/cmdline\n");
+ E("fail to read /proc/cmdline\n");
return -1;
}
if(read_line(fd, cmdline, sizeof(cmdline))) {
D("qemu cmd: %s\n", cmdline);
if (get_str_cmdline(cmdline, split, str, str_size) < 1) {
- D("could not get the (%s) value from cmdline\n", split);
+ E("could not get the (%s) value from cmdline\n", split);
sdb_close(fd);
return -1;
}
s = socket(AF_INET, SOCK_DGRAM, 0);
if(s < 0) {
- D("socket error\n");
+ E("socket error\n");
return -1;
}
snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", GUEST_IP_INTERFACE);
if(ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
- D("ioctl hwaddr error\n");
+ E("ioctl hwaddr error\n");
sdb_close(s);
return -1;
}
if(ioctl(s, SIOCGIFADDR, &ifr) < 0) {
- D("ioctl addr error\n");
+ E("ioctl addr error\n");
sdb_close(s);
return -1;
}
}
if(!strcmp(type, "bootloader")){
- D("setting connection_state to CS_BOOTLOADER\n");
+ I("setting connection_state to CS_BOOTLOADER\n");
t->connection_state = CS_BOOTLOADER;
update_transports();
return;
}
if(!strcmp(type, "device")) {
- D("setting connection_state to CS_DEVICE\n");
+ I("setting connection_state to CS_DEVICE\n");
t->connection_state = CS_DEVICE;
update_transports();
return;
}
if(!strcmp(type, "recovery")) {
- D("setting connection_state to CS_RECOVERY\n");
+ I("setting connection_state to CS_RECOVERY\n");
t->connection_state = CS_RECOVERY;
update_transports();
return;
}
if(!strcmp(type, "sideload")) {
- D("setting connection_state to CS_SIDELOAD\n");
+ I("setting connection_state to CS_SIDELOAD\n");
t->connection_state = CS_SIDELOAD;
update_transports();
return;
asocket *s;
- D("handle_packet() %c%c%c%c\n", ((char*) (&(p->msg.command)))[0],
- ((char*) (&(p->msg.command)))[1],
- ((char*) (&(p->msg.command)))[2],
- ((char*) (&(p->msg.command)))[3]);
+// D("handle_packet() %c%c%c%c\n", ((char*) (&(p->msg.command)))[0],
+// ((char*) (&(p->msg.command)))[1],
+// ((char*) (&(p->msg.command)))[2],
+// ((char*) (&(p->msg.command)))[3]);
print_packet("recv", p);
case A_OPEN: /* OPEN(local-id, 0, "destination") */
if (request_lock_state_to_plugin(LOCKTYPE_PASSWORD) == 1 && t->connection_state == CS_PWLOCK) {
// in case of already locked before get A_CNXN
- D("open failed due to password locked before get A_CNXN:%d\n", t->connection_state);
+ E("open failed due to password locked before get A_CNXN:%d\n", t->connection_state);
send_close(0, p->msg.arg0, t);
} else {
if(t->connection_state != CS_OFFLINE) {
p->len = p->msg.data_length;
if(s->enqueue(s, p) == 0) {
- D("Enqueue the socket\n");
+ I("Enqueue the socket\n");
send_ready(s->id, rid, t);
}
return;
static void ss_listener_event_func(int _fd, unsigned ev, void *_l)
{
asocket *s;
+ int ret = -1;
if(ev & FDE_READ) {
struct sockaddr addr;
fd = sdb_socket_accept(_fd, &addr, &alen);
if(fd < 0) return;
- sdb_socket_setbufsize(fd, CHUNK_SIZE);
+ ret = sdb_socket_setbufsize(fd, CHUNK_SIZE);
+ if (ret == -1) {
+ D("sdbd: sdb_socket_setbufsize failed (%d)\n", ret);
+ }
s = create_local_socket(fd);
if(s) {
}
if (close_on_exec(l->fd) < 0) {
- D("fail to close fd exec:%d\n",l->fd);
+ E("fail to close fd exec:%d\n",l->fd);
}
if(!strcmp(l->connect_to, "*smartsocket*")) {
fdevent_install(&l->fde, l->fd, ss_listener_event_func, l);
unload_sdbd_plugin();
}
+static void sdb_service_cleanup(void)
+{
+ if (exit_cleanup_required)
+ {
+ unload_sdbd_service_plugin();
+ }
+}
+
+
void start_device_log(void)
{
int fd;
- char path[PATH_MAX] = {0, };
+ char path[2*PATH_MAX] = {0, };
char path_folder[PATH_MAX] = {0, };
char path_file[PATH_MAX] = {0, };
struct tm now;
}
int should_drop_privileges() {
- if (rootshell_mode == 1) { // if root, then don't drop
- return 0;
- }
- return 1;
+ return !rootshell_mode; // if root, then don't drop
}
#include <gio/gio.h>
-#define DEVICED_BUS "org.tizen.system.deviced"
-#define DEVICED_CORE_PATH "/Org/Tizen/System/DeviceD/Core"
+#define BOOTING_DONE_PATH "/org/tizen/system"
#define BOOTING_DONE_SIGNAL "BootingDone"
-#define DEVICED_CORE_INTERFACE "org.tizen.system.deviced.core"
+#define BOOTING_DONE_INTERFACE "org.tizen.system.Booting"
#define SDBD_BOOT_INFO_FILE "/tmp/sdbd_boot_info"
static GMainLoop *g_mainloop;
booting_done = 1;
if (access(SDBD_BOOT_INFO_FILE, F_OK) == 0) {
- D("booting is already done\n");
+ I("booting is already done\n");
} else {
FILE *info_file = fopen(SDBD_BOOT_INFO_FILE, "w");
if (info_file != NULL) {
- fprintf(info_file, "%d", 1);
- fclose(info_file);
+ char* tmppath = realpath(SDBD_BOOT_INFO_FILE, NULL);
+ if (tmppath != NULL) {
+ if (strcmp(SDBD_BOOT_INFO_FILE, tmppath) == 0) {
+ fprintf(info_file, "%d", 1);
+ I("booting is done\n");
+ } else {
+ D("Path has symbolic link, security risk \n");
+ free(tmppath);
+ return;
+ }
+ free(tmppath);
+ } else {
+ D("Getting realpath failed\n");
+ }
+ fclose(info_file);
}
- D("booting is done\n");
}
- D("handled the booting done signal\n");
+ I("handled the booting done signal\n");
g_main_loop_quit(g_mainloop);
}
connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (connection == NULL) {
if (error != NULL) {
- D("failed to connect to the system bus: %s\n", error->message);
+ E("failed to connect to the system bus: %s\n", error->message);
g_error_free(error);
} else {
- D("failed to connect to the system bus\n");
+ E("failed to connect to the system bus\n");
}
return NULL;
}
g_mainloop = g_main_loop_new(NULL, false);
if (g_mainloop == NULL) {
- D("failed to create a g_main_loop\n");
+ E("failed to create a g_main_loop\n");
goto bootdone_out;
}
id = g_dbus_connection_signal_subscribe(connection,
- DEVICED_BUS, DEVICED_CORE_INTERFACE, BOOTING_DONE_SIGNAL,
- DEVICED_CORE_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+ NULL, BOOTING_DONE_INTERFACE, BOOTING_DONE_SIGNAL,
+ BOOTING_DONE_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
booting_done_signal_subscriber, NULL, NULL);
if (id == 0) {
- D("failed to subscribe to the booting done signal\n");
+ E("failed to subscribe to the booting done signal\n");
goto bootdone_out;
}
- D("wait for the booting done signal\n");
+ I("wait for the booting done signal\n");
g_main_loop_run(g_mainloop);
g_dbus_connection_signal_unsubscribe(connection, id);
if (connection != NULL) {
g_object_unref(connection);
}
- D("exit the bootdone_cb thread\n");
+ I("exit the bootdone_cb thread\n");
return NULL;
}
{
sdb_thread_t t;
if (sdb_thread_create(&t, bootdone_cb, NULL)) {
- D("can not create a service thread to check the booting done\n");
+ E("can not create a service thread to check the booting done\n");
return;
}
- D("created the bootdone_cb thread\n");
+ I("created the bootdone_cb thread\n");
}
static int sdbd_set_groups(const char *name, int gid, struct group_info default_groups[], int default_groups_size) {
int group_match = 0;
int added_group_cnt = 0;
- getgrouplist(name, gid, NULL, &ngroups);
- D("group list : ngroups = %d\n", ngroups);
+ if (getgrouplist(name, gid, NULL, &ngroups) == -1) {
+ D("group list : ngroups = %d\n", ngroups);
+ }
group_ids = malloc((ngroups + default_groups_size) * sizeof(gid_t));
if (group_ids == NULL) {
- D("failed to allocate group_ids(%zu)\n", (ngroups + default_groups_size) * sizeof(gid_t));
+ E("failed to allocate group_ids(%zu)\n", (ngroups + default_groups_size) * sizeof(gid_t));
return -1;
}
if (getgrouplist(name, gid, group_ids, &ngroups) == -1) {
- D("failed to getgrouplist(), ngroups = %d\n", ngroups);
+ E("failed to getgrouplist(), ngroups = %d\n", ngroups);
free(group_ids);
return -1;
}
}
}
if (setgroups(ngroups+added_group_cnt, group_ids) != 0) {
- D("failed to setgroups().\n");
+ E("failed to setgroups().\n");
free(group_ids);
return -1;
}
ret = getpwnam_r(user_name, pwd, buf, bufsize, &result);
if (result == NULL) {
if (ret == 0) {
- D("Not found passwd : username(%s)\n", user_name);
+ E("Not found passwd : username(%s)\n", user_name);
} else {
errno = ret;
- D("failed to getpwnam_r\n");
+ E("failed to getpwnam_r\n");
}
return -1;
}
ret = getgrnam_r(group_name, grp, buf, bufsize, &result);
if (result == NULL) {
if (ret == 0) {
- D("Not found group : groupname(%s)\n", group_name);
+ E("Not found group : groupname(%s)\n", group_name);
} else {
errno = ret;
- D("failed to getgrnam_r\n");
+ E("failed to getgrnam_r\n");
}
return -1;
}
int set_sdk_user_privileges(int is_drop_capability_after_fork) {
if (!is_init_sdk_userinfo) {
- D("failed to init sdk user information.\n");
+ E("failed to init sdk user information.\n");
return -1;
}
if(is_drop_capability_after_fork) {
if (setuid(g_root_user_id) != 0) {
- D("set root user id failed (errno: %d)\n", errno);
+ E("set root user id failed (errno: %d)\n", errno);
return -1;
}
}
if (sdbd_set_groups(SDK_USER_NAME, g_sdk_group_id, g_default_groups, SDB_DEFAULT_GROUPS_CNT) < 0) {
- D("set groups failed (errno: %d)\n", errno);
+ E("set groups failed (errno: %d)\n", errno);
return -1;
}
if (setgid(g_sdk_group_id) != 0) {
- D("set group id failed (errno: %d)\n", errno);
+ E("set group id failed (errno: %d)\n", errno);
return -1;
}
if (setuid(g_sdk_user_id) != 0) {
- D("set user id failed (errno: %d)\n", errno);
+ E("set user id failed (errno: %d)\n", errno);
return -1;
// if(is_drop_capability_after_fork) {
// return -1;
}
if (chdir(g_sdk_home_dir) < 0) {
- D("unable to change working directory to %s\n", g_sdk_home_dir);
+ E("unable to change working directory to %s\n", g_sdk_home_dir);
}
// TODO: use pam later
int set_root_privileges() {
if (sdbd_set_groups(ROOT_USER_NAME, g_root_group_id, NULL, 0) < 0) {
- D("set root groups failed (errno: %d)\n", errno);
+ E("set root groups failed (errno: %d)\n", errno);
}
if (setgid(g_root_group_id) != 0) {
- D("set root group id failed (errno: %d)\n", errno);
+ E("set root group id failed (errno: %d)\n", errno);
}
if (setuid(g_root_user_id) != 0) {
- D("set root user id failed (errno: %d)\n", errno);
+ E("set root user id failed (errno: %d)\n", errno);
}
if (chdir(g_root_home_dir) < 0) {
- D("unable to change root working directory to %s\n", g_sdk_home_dir);
+ E("unable to change root working directory to %s\n", g_sdk_home_dir);
}
// TODO: use pam later
bufsize = get_group_bufsize();
buf = malloc(bufsize);
if (buf == NULL) {
- D("failed to allocate gruop buf(%ld)\n", bufsize);
+ E("failed to allocate gruop buf(%ld)\n", bufsize);
return -1;
}
if (sdbd_get_group(g_default_groups[i].name, &grp, buf, bufsize) == 0) {
g_default_groups[i].gid = grp.gr_gid;
} else {
- D("failed get group info.(errno: %d)\n", errno);
+ E("failed get group info.(errno: %d)\n", errno);
}
}
bufsize = get_passwd_bufsize();
buf = malloc(bufsize);
if (buf == NULL) {
- D("failed to allocate passwd buf(%ld)\n", bufsize);
+ E("failed to allocate passwd buf(%ld)\n", bufsize);
set_static_root_userinfo();
} else {
if (sdbd_get_user_pwd(ROOT_USER_NAME, &pwd, buf, bufsize) < 0) {
- D("failed to get root user passwd info.(errno: %d)\n", errno);
+ E("failed to get root user passwd info.(errno: %d)\n", errno);
set_static_root_userinfo();
} else {
D("username=%s, uid=%d, gid=%d, dir=%s\n", pwd.pw_name, pwd.pw_uid, pwd.pw_gid, pwd.pw_dir);
int env_size = strlen("HOME=") + strlen(g_root_home_dir) + 1;
g_root_home_dir_env = malloc(env_size);
if(g_root_home_dir_env == NULL) {
- D("failed to allocate for home dir env string\n");
+ E("failed to allocate for home dir env string\n");
} else {
snprintf(g_root_home_dir_env, env_size, "HOME=%s", g_root_home_dir);
}
}
if (init_sdb_default_groups() < 0) {
- D("failed to initialize default groups.\n");
+ E("failed to initialize default groups.\n");
}
bufsize = get_passwd_bufsize();
buf = malloc(bufsize);
if (buf == NULL) {
- D("failed to allocate passwd buf(%ld)\n", bufsize);
+ E("failed to allocate passwd buf(%ld)\n", bufsize);
set_static_sdk_userinfo();
} else {
if (sdbd_get_user_pwd(SDK_USER_NAME, &pwd, buf, bufsize) < 0) {
- D("get user passwd info.(errno: %d)\n", errno);
+ E("get user passwd info.(errno: %d)\n", errno);
set_static_sdk_userinfo();
} else {
D("username=%s, uid=%d, gid=%d, dir=%s\n", pwd.pw_name, pwd.pw_uid, pwd.pw_gid, pwd.pw_dir);
int env_size = strlen("HOME=") + strlen(g_sdk_home_dir) + 1;
g_sdk_home_dir_env = malloc(env_size);
if(g_sdk_home_dir_env == NULL) {
- D("failed to allocate for home dir env string\n");
+ E("failed to allocate for home dir env string\n");
} else {
snprintf(g_sdk_home_dir_env, env_size, "HOME=%s", g_sdk_home_dir);
}
return 0;
}
+#if 0
static int safe_system(char *cmd, char *argv[], char *envp[]) {
pid_t pid;
int status;
return -1;
case 0:
execve(cmd, argv, envp);
- D("- exec '%s' failed: (errno:%d) -\n", cmd, errno);
+ E("- exec '%s' failed: (errno:%d) -\n", cmd, errno);
exit(-1);
default:
for (;;) {
}
return 0;
}
+#endif
static void init_sdk_requirements() {
- struct stat st;
-
// set env variable for temporary
// TODO: should use pam instead later!!
putenv("TERM=linux");
init_sdk_userinfo();
init_root_userinfo();
- if (g_sdk_home_dir != NULL && stat(g_sdk_home_dir, &st) == 0) {
- if (st.st_uid != g_sdk_user_id || st.st_gid != g_sdk_group_id) {
- char* cmd = "/usr/bin/chown";
- char params[128];
- char* envp[128];
- int envp_cnt = 0;
- int i = 0;
-
- envp[envp_cnt++] = g_strdup("TERM=linux");
- envp[envp_cnt++] = g_strdup("DISPLAY=:0");
- envp[envp_cnt] = NULL;
-
- snprintf(params, sizeof(params), "%s %s:%s %s -R", cmd, SDK_USER_NAME, SDK_USER_NAME, g_sdk_home_dir);
-
- char* args[] = {
- cmd,
- params,
- NULL,
- };
- if (safe_system(cmd, args, envp) < 0) {
- D("failed to change ownership to sdk user to %s\n", g_sdk_home_dir);
- }
-
- /* free environment variables */
- if (envp_cnt > 0) {
- for (i = 0; i < envp_cnt; i++) {
- if (envp[i]) {
- g_free(envp[i]);
- }
- }
- }
- }
- }
-
if (is_emulator()) {
register_bootdone_cb();
}
memset(&g_capabilities, 0, sizeof(g_capabilities));
+ // architecture support
+ char* arch = get_platfrom_architecture();
+ snprintf(g_capabilities.architecture, sizeof(g_capabilities.architecture),
+ "%s", arch);
+
// CPU Architecture of model
ret = system_info_get_platform_string("http://tizen.org/feature/platform.core.cpu.arch", &value);
if (ret != SYSTEM_INFO_ERROR_NONE) {
snprintf(g_capabilities.cpu_arch, sizeof(g_capabilities.cpu_arch),
"%s", UNKNOWN);
- D("fail to get the CPU architecture of model:%d\n", errno);
+ E("fail to get the CPU architecture of model:%d\n", errno);
+ } else {
+ if (value != NULL) {
+ // check for armv8 and 32 bit architecture, for it make the cpu arch as armv7l
+ if(!strncmp(value,"armv8",sizeof("armv8")+1) && !strncmp(arch,"32",sizeof("32")+1))
+ {
+ D("Changing cpu arch in capability from %s to %s for %s bit\n",value,"armv7l",arch);
+ snprintf(g_capabilities.cpu_arch, sizeof(g_capabilities.cpu_arch),
+ "%s", "armv7l");
+ } else {
+ snprintf(g_capabilities.cpu_arch, sizeof(g_capabilities.cpu_arch),
+ "%s", value);
+ }
+ free(value);
+ }
+ }
+
+ // Core ABI (That value can be a "arm_32", "arm_64", "riscv_32", "riscv_64", "x86", "x86_64")
+ ret = system_info_get_platform_string("http://tizen.org/feature/platform.core.abi", &value);
+ if (ret != SYSTEM_INFO_ERROR_NONE) {
+ snprintf(g_capabilities.core_abi, sizeof(g_capabilities.core_abi),
+ "%s", UNKNOWN);
+ E("fail to get the core abi:%d\n", errno);
} else {
- snprintf(g_capabilities.cpu_arch, sizeof(g_capabilities.cpu_arch),
- "%s", value);
if (value != NULL) {
+ snprintf(g_capabilities.core_abi, sizeof(g_capabilities.core_abi), "%s", value);
free(value);
}
}
// Secure protocol support
if(!request_capability_to_plugin(CAPABILITY_SECURE, g_capabilities.secure_protocol,
sizeof(g_capabilities.secure_protocol))) {
- D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_SECURE);
+ E("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_SECURE);
snprintf(g_capabilities.secure_protocol, sizeof(g_capabilities.secure_protocol),
"%s", DISABLED);
}
// Interactive shell support
if(!request_capability_to_plugin(CAPABILITY_INTER_SHELL, g_capabilities.intershell_support,
sizeof(g_capabilities.intershell_support))) {
- D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_INTER_SHELL);
+ E("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_INTER_SHELL);
snprintf(g_capabilities.intershell_support, sizeof(g_capabilities.intershell_support),
"%s", DISABLED);
}
// File push/pull support
if(!request_capability_to_plugin(CAPABILITY_FILESYNC, g_capabilities.filesync_support,
sizeof(g_capabilities.filesync_support))) {
- D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_FILESYNC);
+ E("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_FILESYNC);
snprintf(g_capabilities.filesync_support, sizeof(g_capabilities.filesync_support),
"%s", DISABLED);
}
// USB protocol support
if(!request_capability_to_plugin(CAPABILITY_USB_PROTOCOL, g_capabilities.usbproto_support,
sizeof(g_capabilities.usbproto_support))) {
- D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_USB_PROTOCOL);
+ E("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_USB_PROTOCOL);
snprintf(g_capabilities.usbproto_support, sizeof(g_capabilities.usbproto_support),
"%s", DISABLED);
}
// Socket protocol support
if(!request_capability_to_plugin(CAPABILITY_SOCK_PROTOCOL, g_capabilities.sockproto_support,
sizeof(g_capabilities.sockproto_support))) {
- D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_SOCK_PROTOCOL);
+ E("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_SOCK_PROTOCOL);
snprintf(g_capabilities.sockproto_support, sizeof(g_capabilities.sockproto_support),
"%s", DISABLED);
}
// Root command support
if(!request_capability_to_plugin(CAPABILITY_ROOT_ONOFF, g_capabilities.rootonoff_support,
sizeof(g_capabilities.rootonoff_support))) {
- D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_ROOT_ONOFF);
+ E("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_ROOT_ONOFF);
snprintf(g_capabilities.rootonoff_support, sizeof(g_capabilities.rootonoff_support),
"%s", DISABLED);
}
// Encryption support
if(!request_capability_to_plugin(CAPABILITY_ENCRYPTION, g_capabilities.encryption_support,
sizeof(g_capabilities.encryption_support))) {
- D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_ENCRYPTION);
+ E("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_ENCRYPTION);
snprintf(g_capabilities.encryption_support, sizeof(g_capabilities.encryption_support),
"%s", DISABLED);
}
// SDK Tool path
if (SDK_TOOL_PATH == NULL) {
- D("fail to get SDK tool path.\n");
+ E("fail to get SDK tool path.\n");
snprintf(g_capabilities.sdk_toolpath, sizeof(g_capabilities.sdk_toolpath),
"%s", UNKNOWN);
} else {
if (ret != SYSTEM_INFO_ERROR_NONE) {
snprintf(g_capabilities.profile_name, sizeof(g_capabilities.profile_name),
"%s", UNKNOWN);
- D("fail to get profile name:%d\n", errno);
+ E("fail to get profile name:%d\n", errno);
} else {
snprintf(g_capabilities.profile_name, sizeof(g_capabilities.profile_name),
"%s", value);
if (ret != SYSTEM_INFO_ERROR_NONE) {
snprintf(g_capabilities.vendor_name, sizeof(g_capabilities.vendor_name),
"%s", UNKNOWN);
- D("fail to get the Vendor name:%d\n", errno);
+ E("fail to get the Vendor name:%d\n", errno);
} else {
snprintf(g_capabilities.vendor_name, sizeof(g_capabilities.vendor_name),
"%s", value);
// Target name of the launch possible
if(!request_capability_to_plugin(CAPABILITY_CAN_LAUNCH, g_capabilities.can_launch,
sizeof(g_capabilities.can_launch))) {
- D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_CAN_LAUNCH);
+ E("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_CAN_LAUNCH);
snprintf(g_capabilities.can_launch, sizeof(g_capabilities.can_launch),
"%s", UNKNOWN);
}
} else {
snprintf(g_capabilities.device_name, sizeof(g_capabilities.device_name),
"%s", UNKNOWN);
- D("fail to get the Device name:%d\n", errno);
+ E("fail to get the Device name:%d\n", errno);
}
if (ret != SYSTEM_INFO_ERROR_NONE) {
snprintf(g_capabilities.platform_version, sizeof(g_capabilities.platform_version),
"%s", UNKNOWN);
- D("fail to get platform version:%d\n", errno);
+ E("fail to get platform version:%d\n", errno);
} else {
snprintf(g_capabilities.platform_version, sizeof(g_capabilities.platform_version),
"%s", value);
// Product version
if(!request_capability_to_plugin(CAPABILITY_PRODUCT_VER, g_capabilities.product_version,
sizeof(g_capabilities.product_version))) {
- D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_PRODUCT_VER);
+ E("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_PRODUCT_VER);
snprintf(g_capabilities.product_version, sizeof(g_capabilities.product_version),
"%s", UNKNOWN);
}
// Sdbd plugin version
if(!request_capability_to_plugin(CAPABILITY_PLUGIN_VER, g_capabilities.sdbd_plugin_version,
sizeof(g_capabilities.sdbd_plugin_version))) {
- D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_PLUGIN_VER);
+ E("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_PLUGIN_VER);
snprintf(g_capabilities.sdbd_plugin_version, sizeof(g_capabilities.sdbd_plugin_version),
"%s", UNKNOWN);
}
// sdbd log enable
if(!request_capability_to_plugin(CAPABILITY_LOG_ENABLE, g_capabilities.log_enable,
sizeof(g_capabilities.log_enable))) {
- D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_LOG_ENABLE);
+ E("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_LOG_ENABLE);
snprintf(g_capabilities.log_enable, sizeof(g_capabilities.log_enable),
"%s", DISABLED);
}
// sdbd log path
if(!request_capability_to_plugin(CAPABILITY_LOG_PATH, g_capabilities.log_path,
sizeof(g_capabilities.log_path))) {
- D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_LOG_PATH);
+ E("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_LOG_PATH);
snprintf(g_capabilities.log_path, sizeof(g_capabilities.log_path),
"%s", UNKNOWN);
}
// Application command support
if(!request_capability_to_plugin(CAPABILITY_APPCMD, g_capabilities.appcmd_support,
sizeof(g_capabilities.appcmd_support))) {
- D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_APPCMD);
+ E("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_APPCMD);
snprintf(g_capabilities.appcmd_support, sizeof(g_capabilities.appcmd_support),
"%s", UNKNOWN);
}
// pkgcmd debug mode support
if(!request_capability_to_plugin(CAPABILITY_DEBUGMODE, g_capabilities.pkgcmd_debugmode,
sizeof(g_capabilities.pkgcmd_debugmode))) {
- D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_DEBUGMODE);
+ E("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_DEBUGMODE);
snprintf(g_capabilities.pkgcmd_debugmode, sizeof(g_capabilities.pkgcmd_debugmode),
"%s", ENABLED);
}
+ // netcore debugger support
+ ret = is_netcoredbg_supported();
+ snprintf(g_capabilities.netcoredbg_support, sizeof(g_capabilities.netcoredbg_support),
+ "%s", ret == 1 ? ENABLED : DISABLED);
+
// Capability version
snprintf(g_capabilities.sdbd_cap_version, sizeof(g_capabilities.sdbd_cap_version),
"%d.%d", SDBD_CAP_VERSION_MAJOR, SDBD_CAP_VERSION_MINOR);
static int is_support_usbproto()
{
- return (!strncmp(g_capabilities.usbproto_support, PLUGIN_RET_ENABLED, strlen(PLUGIN_RET_ENABLED)));
+ return (!strncmp(g_capabilities.usbproto_support, PLUGIN_RET_ENABLED, strlen(PLUGIN_RET_ENABLED)+1));
}
static int is_support_sockproto()
{
- return (!strncmp(g_capabilities.sockproto_support, PLUGIN_RET_ENABLED, strlen(PLUGIN_RET_ENABLED)));
+ return (!strncmp(g_capabilities.sockproto_support, PLUGIN_RET_ENABLED, strlen(PLUGIN_RET_ENABLED)+1));
}
#define EMULATOR_MODEL_NAME "Emulator"
// Get the model name from model_config.xml
ret = get_device_name(model_name, sizeof model_name);
if (ret == 0) {
- if(!strncmp(model_name, EMULATOR_MODEL_NAME, sizeof(EMULATOR_MODEL_NAME))){
+ if(!strncmp(model_name, EMULATOR_MODEL_NAME, strlen("Emulator")+1)){
g_is_emulator = 1;
- D("This target type is Emulator\n");
+ I("This target type is Emulator\n");
} else {
g_is_emulator = 0;
- D("This target type is Device\n");
+ I("This target type is Device\n");
}
} else {
g_is_emulator = -1;
- D("failed to get the model name.\n");
+ E("failed to get the model name.\n");
}
}
init_capabilities();
- sdb_trace_init();
- start_device_log();
+ //sdb_trace_init();
+ //start_device_log();
init_drop_privileges();
init_sdk_requirements();
if (!request_validity_to_plugin(PLUGIN_SYNC_CMD_VERIFY_LAUNCH, NULL)) {
- D("sdbd should be launched in develop mode.\n");
+ E("sdbd should be launched in develop mode.\n");
return -1;
}
cap.inheritable = 0;
capset(&header, &cap);
#endif
- D("Local port disabled\n");
+ I("Local port disabled\n");
} else {
char local_name[30];
build_local_name(local_name, sizeof(local_name), server_port);
D("sdb_main(): post init_jdwp()\n");
#endif
- D("Event loop starting\n");
+ sdb_notify_startup(0, "READY=1");
+
+ I("Event loop starting\n");
fdevent_loop();
return 0;
}
+void sdb_main_service()
+{
+ load_sdbd_plugin();
+ init_capabilities();
+ init_sdk_requirements();
+ atexit(sdb_service_cleanup);
+}
+
int copy_packet(apacket* dest, apacket* src) {
if(dest == NULL) {
- D("dest packet is NULL\n");
+ E("dest packet is NULL\n");
return -1;
}
if(src == NULL) {
- D("src packet is NULL\n");
+ E("src packet is NULL\n");
return -1;
}
}
return -1;
}
-
-int recovery_mode = 0;
-
-int main(int argc, char **argv)
-{
- /* If sdbd runs inside the emulator this will enable sdb tracing via
- * sdb-debug qemud service in the emulator. */
-#if 0 /* tizen specific */
- sdb_qemu_trace_init();
- if((argc > 1) && (!strcmp(argv[1],"recovery"))) {
- sdb_device_banner = "recovery";
- recovery_mode = 1;
- }
-#endif
-
- apply_sdbd_commandline_defaults(&sdbd_commandline_args);
- int parse_ret = parse_sdbd_commandline(&sdbd_commandline_args, argc, argv);
-
- // TODO: Add detailed error messages
- // TODO: Add individual messages for help and usage
- if(parse_ret != SDBD_COMMANDLINE_SUCCESS) {
- if (parse_ret == SDBD_COMMANDLINE_HELP
- || parse_ret == SDBD_COMMANDLINE_USAGE) {
- // User requested help or usage
- print_sdbd_usage_message(stdout);
- return EXIT_SUCCESS;
- }
-
- // Print usage message because of invalid options
- print_sdbd_usage_message(stderr);
- return EXIT_FAILURE;
- }
-
- D("Handling main()\n");
-
- //sdbd will never die on emulator!
- signal(SIGTERM, handle_sig_term); /* tizen specific */
- return sdb_main(DEFAULT_SDB_PORT);
-}
-