src/plugin.c
src/plugin_encrypt.c
src/descs_strings.c
+ src/sdbd.c
)
+
+SET(SDBD_SERVICE_SRCS
+ src/sdb.c
+ src/fdevent.c
+ src/transport.c
+ src/transport_local.c
+ src/transport_usb.c
+ src/sockets.c
+ src/file_sync_service.c
+ src/usb_linux_client.c
+ src/utils.c
+ src/socket_inaddr_any_server.c
+ src/socket_local_client.c
+ src/socket_local_server.c
+ src/socket_loopback_client.c
+ src/socket_loopback_server.c
+ src/socket_network_client.c
+ src/sdktools.c
+ src/strutils.c
+ src/commandline_sdbd.c
+ src/usb_linux_client.c
+ src/usb_funcfs_client.c
+ src/default_plugin_auth.c
+ src/default_plugin_basic.c
+ src/default_plugin_main.c
+ src/default_plugin_event.c
+ src/default_plugin_appcmd.c
+ src/default_plugin_shellcmd.c
+ src/hashtable.c
+ src/plugin.c
+ src/plugin_encrypt.c
+ src/descs_strings.c
+ src/services.c
+ src/sdbd_service.c
+)
+
SET(SDBD_SUBS
src/subprocess.c
)
ADD_EXECUTABLE(sdbd ${SDBD_SRCS})
ADD_EXECUTABLE(sdbd-user ${SDBD_SUBS})
+ADD_EXECUTABLE(sdbd-service ${SDBD_SERVICE_SRCS})
TARGET_LINK_LIBRARIES(sdbd -pie -lsmack -lresolv -ldl ${CMAKE_THREAD_LIBS_INIT} ${pkgs_LDFLAGS} ${SYSTEMD_LDFLAGS})
+TARGET_LINK_LIBRARIES(sdbd-service -pie -lsmack -lresolv -ldl ${CMAKE_THREAD_LIBS_INIT} ${pkgs_LDFLAGS} ${SYSTEMD_LDFLAGS})
TARGET_LINK_LIBRARIES(sdbd-user -pie ${CMAKE_THREAD_LIBS_INIT} ${pkgs_LDFLAGS})
set_property(
HAVE_FORKEXEC
)
+set_property(
+ TARGET sdbd-service
+ PROPERTY COMPILE_DEFINITIONS
+ SDB_HOST=0
+ _DROP_PRIVILEGE
+ _FILE_OFFSET_BITS=64
+)
+
+set_property(
+ TARGET sdbd-service
+ APPEND PROPERTY COMPILE_DEFINITIONS
+ _XOPEN_SOURCE
+ _GNU_SOURCE
+ HAVE_FORKEXEC
+)
+
+
if(USE_FUNCTION_FS)
set_property(
TARGET sdbd
)
endif()
-install(TARGETS sdbd sdbd-user DESTINATION /usr/sbin)
+install(TARGETS sdbd sdbd-user sdbd-service DESTINATION /usr/sbin)
install(FILES script/sdbd DESTINATION /etc/init.d)
# Extract descriptors and strings for systemd socket activation
%defattr(-,root,root,-)
%{_prefix}/sbin/sdbd
%{_prefix}/sbin/sdbd-user
+%{_prefix}/sbin/sdbd-service
%{_prefix}/sbin/sdk_launch
%attr(0755, root, root) %{_sysconfdir}/init.d/sdbd
%{_unitdir}/sdbd.service
#define SYNC_DATA_MAX (64*1024)
+#define EXEC_AFTER_FORK 1 //with this enabled sdbd-service will be used for file sync services
+
#endif
-/*
+/*
* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
#endif
#include <linux/prctl.h>
-#define SDB_PIDPATH "/tmp/.sdbd.pid"
#include <system_info.h>
#include <vconf.h>
#include <glib.h>
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();
}
}
-void handle_sig_term(int sig) {
-#ifdef SDB_PIDPATH
- if (access(SDB_PIDPATH, F_OK) == 0)
- sdb_unlink(SDB_PIDPATH);
-#endif
- exit(0);
-}
static const char *sdb_device_banner = "device";
return 0;
}
+void sdb_main_service()
+{
+ init_capabilities();
+ init_sdk_requirements();
+}
+
int copy_packet(apacket* dest, apacket* src) {
if(dest == NULL) {
return 0;
}
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;
- }
-
- I("Handling main()\n");
-
- //sdbd will never die on emulator!
- signal(SIGTERM, handle_sig_term); /* tizen specific */
- return sdb_main(DEFAULT_SDB_PORT);
-}
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include "sdb.h"
+#include "sysdeps.h"
+#include "commandline_sdbd.h"
+#define LOG_TAG "SDBD_TRACE_SDB"
+#include "log.h"
+
+extern SdbdCommandlineArgs sdbd_commandline_args;
+
+#define SDB_PIDPATH "/tmp/.sdbd.pid"
+
+void handle_sig_term(int sig) {
+#ifdef SDB_PIDPATH
+ if (access(SDB_PIDPATH, F_OK) == 0)
+ sdb_unlink(SDB_PIDPATH);
+#endif
+ exit(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;
+ }
+
+ I("Handling main()\n");
+
+ //sdbd will never die on emulator!
+ signal(SIGTERM, handle_sig_term); /* tizen specific */
+ return sdb_main(DEFAULT_SDB_PORT);
+}
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define TRACE_TAG TRACE_SDB
+#define LOG_TAG "SDBD_TRACE_SDB"
+#include "log.h"
+#include "sdb.h"
+#include "file_sync_service.h"
+
+extern void sdb_main_service();
+
+int main(int argc, char* argv[]) {
+ sdb_main_service();
+ int fd=atoi(argv[1]);
+ D("SERVICE In child process fd=%d",fd);
+ const char* cookie = argv[2];
+ D("SERVICE In child process cookie=%s",cookie);
+ rootshell_mode = atoi(argv[3]);
+ D("SERVICE In child process rootshell_mode=%d",rootshell_mode);
+ file_sync_service(fd, (void*)cookie);
+ D("SERVICE after file sync");
+ exit(0);
+}
sdb_thread_t t;
int s[2];
+#ifdef EXEC_AFTER_FORK
+ if(sdb_socketpair_without_execclose(s)) {
+ E("cannot create service socket pair\n");
+ return -1;
+ }
+#else
if(sdb_socketpair(s)) {
E("cannot create service socket pair\n");
return -1;
}
+#endif
+ D("SERVICE create_sync_subprocess cookie=%s\n",(char*)cookie);
pid_t pid = fork();
if (pid == 0) {
sdb_close(s[0]);
+#ifdef EXEC_AFTER_FORK
+ // exec the new process to do file sync
+ char *fname="/usr/sbin/sdbd-service";
+ char *arg[5];
+ char targ[10];
+ char smarg[10];
+ sprintf(targ,"%d",s[1]);
+ sprintf(smarg, "%d",rootshell_mode);
+ D("SERVICE fd to be used by child process %d",s[1]);
+ D("SERVICE rootmode to be used by child process %s",smarg);
+ arg[0]=fname;
+ arg[1]=targ;
+ arg[2]= strdup((char*)cookie);
+ D("SERVICE cookie to be used by child process %s",arg[2]);
+ arg[3]=smarg;
+ arg[4]=NULL;
+ execvp(fname,arg);
+#else
func(s[1], cookie);
exit(-1);
+#endif
} else if (pid > 0) {
+ D("SERVICE fd passed by parent process %d",s[1]);
sdb_close(s[1]);
// FIXME: do not wait child process hear
//waitpid(pid, &ret, 0);
return 0;
}
+static __inline__ int sdb_socketpair_without_execclose( int sv[2] )
+{
+ int rc;
+
+ rc = unix_socketpair( AF_UNIX, SOCK_STREAM, 0, sv );
+ if (rc < 0) {
+ return -1;
+ }
+ return 0;
+}
+
#undef socketpair
#define socketpair ___xxx_socketpair