int main(void) { fuse_init(); pin_init(); serial_init(); while (1) { serial_println("Hello"); __delay_ms(10); } return 0; }
static int run(const char* source_path, const char* dest_path, uid_t uid, gid_t gid, int num_threads) { int fd; char opts[256]; int res; struct fuse fuse; /* cleanup from previous instance, if necessary */ umount2(dest_path, 2); fd = open("/dev/fuse", O_RDWR); if (fd < 0){ ERROR("cannot open fuse device (error %d)\n", errno); return -1; } res = mount(NULL, "/system", "ext4", MS_NODEV | MS_REMOUNT, opts); snprintf(opts, sizeof(opts), "fd=%i,rootmode=40000,allow_other,user_id=0,group_id=0", fd, uid, gid); res = mount("/dev/fuse", dest_path, "fuse", MS_NODEV, opts); if (res < 0) { ERROR("cannot mount fuse filesystem (error %d)\n", errno); goto error; } res = setgid(gid); if (res < 0) { ERROR("cannot setgid (error %d)\n", errno); goto error; } res = setuid(uid); if (res < 0) { ERROR("cannot setuid (error %d)\n", errno); goto error; } fuse_init(&fuse, fd, source_path); umask(0); res = ignite_fuse(&fuse, num_threads); /* we do not attempt to umount the file system here because we are no longer * running as the root user */ error: close(fd); return res; }
int main(int argc, char **argv) { struct fuse fuse; char opts[256]; int fd; int res; const char *path = NULL; int i; for (i = 1; i < argc; i++) { char* arg = argv[i]; if (!path) path = arg; else if (uid == -1) uid = strtoul(arg, 0, 10); else if (gid == -1) gid = strtoul(arg, 0, 10); else { ERROR("too many arguments\n"); return usage(); } } if (!path) { ERROR("no path specified\n"); return usage(); } if (uid <= 0 || gid <= 0) { ERROR("uid and gid must be nonzero\n"); return usage(); } /* cleanup from previous instance, if necessary */ umount2(MOUNT_POINT, 2); fd = open("/dev/fuse", O_RDWR); if (fd < 0){ ERROR("cannot open fuse device (%d)\n", errno); return -1; } sprintf(opts, "fd=%i,rootmode=40000,default_permissions,allow_other," "user_id=%d,group_id=%d", fd, uid, gid); res = mount("/dev/fuse", MOUNT_POINT, "fuse", MS_NOSUID | MS_NODEV, opts); if (res < 0) { ERROR("cannot mount fuse filesystem (%d)\n", errno); return -1; } if (setgid(gid) < 0) { ERROR("cannot setgid!\n"); return -1; } if (setuid(uid) < 0) { ERROR("cannot setuid!\n"); return -1; } fuse_init(&fuse, fd, path); umask(0); handle_fuse_requests(&fuse); return 0; }
int main(int argc, char **argv) { struct fuse fuse; char opts[256]; int fd; int res; const char *path = NULL; int i; TRACE("starting sdcard service\n"); #ifdef MTK_2SDCARD_SWAP int hasExternalSd = 0; int fd_externalsd; char internal_sd_path[PROPERTY_VALUE_MAX]; property_get("internal_sd_path", internal_sd_path, ""); fd_externalsd = open("/dev/block/mmcblk1", O_RDONLY); if (fd_externalsd < 0){ TRACE("External sd doesn't exist (%d)\n", errno); hasExternalSd = 0; } else { TRACE("External sd exist.\n"); hasExternalSd = 1; close(fd_externalsd); } LOG("hasExternalSd=%d, internal_sd_path = '%s'\n", hasExternalSd, internal_sd_path); #endif for (i = 1; i < argc; i++) { char* arg = argv[i]; if (!path) path = arg; else if (uid == -1) uid = strtoul(arg, 0, 10); else if (gid == -1) gid = strtoul(arg, 0, 10); else { ERROR("too many arguments\n"); return usage(); } } if (!path) { ERROR("no path specified\n"); return usage(); } if (uid <= 0 || gid <= 0) { ERROR("uid and gid must be nonzero\n"); return usage(); } /* cleanup from previous instance, if necessary */ #ifdef MTK_2SDCARD_SWAP if (hasExternalSd) { if (strlen(internal_sd_path) > 0) { umount2(internal_sd_path, 2); } else { umount2(MOUNT_POINT_2, 2); } } else #endif { umount2(MOUNT_POINT, 2); } fd = open("/dev/fuse", O_RDWR); if (fd < 0){ ERROR("cannot open fuse device (%d)\n", errno); return -1; } sprintf(opts, "fd=%i,rootmode=40000,default_permissions,allow_other," "user_id=%d,group_id=%d", fd, uid, gid); #ifdef MTK_2SDCARD_SWAP if (hasExternalSd) { if (strlen(internal_sd_path) > 0) { res = mount("/dev/fuse", internal_sd_path, "fuse", MS_NOSUID | MS_NODEV, opts); } else { res = mount("/dev/fuse", MOUNT_POINT_2, "fuse", MS_NOSUID | MS_NODEV, opts); } } else #endif { res = mount("/dev/fuse", MOUNT_POINT, "fuse", MS_NOSUID | MS_NODEV, opts); } if (res < 0) { ERROR("cannot mount fuse filesystem (%d)\n", errno); return -1; } else { LOG("mount shared sd successfully \n"); } if (setgid(gid) < 0) { ERROR("cannot setgid!\n"); return -1; } if (setuid(uid) < 0) { ERROR("cannot setuid!\n"); return -1; } fuse_init(&fuse, fd, path); umask(0); handle_fuse_requests(&fuse); return 0; }
/* returns error */ static int APP_CC process_message_channel_setup(struct stream *s) { int num_chans; int index; int rv; struct chan_item *ci; g_num_chan_items = 0; g_cliprdr_index = -1; g_rdpsnd_index = -1; g_rdpdr_index = -1; g_rail_index = -1; g_cliprdr_chan_id = -1; g_rdpsnd_chan_id = -1; g_rdpdr_chan_id = -1; g_rail_chan_id = -1; g_drdynvc_chan_id = -1; LOGM((LOG_LEVEL_DEBUG, "process_message_channel_setup:")); in_uint16_le(s, num_chans); LOGM((LOG_LEVEL_DEBUG, "process_message_channel_setup: num_chans %d", num_chans)); for (index = 0; index < num_chans; index++) { ci = &(g_chan_items[g_num_chan_items]); g_memset(ci->name, 0, sizeof(ci->name)); in_uint8a(s, ci->name, 8); in_uint16_le(s, ci->id); in_uint16_le(s, ci->flags); LOGM((LOG_LEVEL_DEBUG, "process_message_channel_setup: chan name '%s' " "id %d flags %8.8x", ci->name, ci->id, ci->flags)); g_writeln("process_message_channel_setup: chan name '%s' " "id %d flags %8.8x", ci->name, ci->id, ci->flags); if (g_strcasecmp(ci->name, "cliprdr") == 0) { g_cliprdr_index = g_num_chan_items; g_cliprdr_chan_id = ci->id; } else if (g_strcasecmp(ci->name, "rdpsnd") == 0) { g_rdpsnd_index = g_num_chan_items; g_rdpsnd_chan_id = ci->id; } else if (g_strcasecmp(ci->name, "rdpdr") == 0) { g_rdpdr_index = g_num_chan_items; g_rdpdr_chan_id = ci->id; } else if (g_strcasecmp(ci->name, "rail") == 0) { g_rail_index = g_num_chan_items; g_rail_chan_id = ci->id; } else if (g_strcasecmp(ci->name, "drdynvc") == 0) { g_drdynvc_index = g_num_chan_items; // LK_TODO use this g_drdynvc_chan_id = ci->id; // LK_TODO use this } else { LOG(10, ("other %s", ci->name)); } g_num_chan_items++; } rv = send_channel_setup_response_message(); if (g_cliprdr_index >= 0) { clipboard_init(); fuse_init(); } if (g_rdpsnd_index >= 0) { sound_init(); } if (g_rdpdr_index >= 0) { dev_redir_init(); } if (g_rail_index >= 0) { rail_init(); } if (g_drdynvc_index >= 0) { g_memset(&g_dvc_channels[0], 0, sizeof(g_dvc_channels)); drdynvc_init(); } return rv; }