Overview
Comment: | Updated to include a Tcl interface via AppFSd |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | tcl-ops |
Files: | files | file ages | folders |
SHA1: | 4b04c967f7016def226576a72537cd516962c086 |
User & Date: | rkeene on 2014-11-07 05:06:43 |
Other Links: | manifest | tags |
Context
2014-11-07
| ||
05:42 | Added more functionality to "appfs-cache" control system check-in: 82982300d8 user: rkeene tags: tcl-ops | |
05:06 | Updated to include a Tcl interface via AppFSd check-in: 4b04c967f7 user: rkeene tags: tcl-ops | |
04:52 | Added support for an "appfs-cache" script calling sqlite3 directly in appfsd check-in: c374111c37 user: rkeene tags: tcl-ops | |
Changes
Modified appfsd.c from [206ee97d58] to [e20407f29f].
143 143 fprintf(stderr, "Tcl Error is: %s\n", Tcl_GetStringResult(interp)); 144 144 145 145 Tcl_DeleteInterp(interp); 146 146 147 147 return(NULL); 148 148 } 149 149 150 - Tcl_HideCommand(interp, "glob", "glob"); 151 - Tcl_HideCommand(interp, "exec", "exec"); 152 - Tcl_HideCommand(interp, "pid", "pid"); 153 150 Tcl_HideCommand(interp, "auto_load_index", "auto_load_index"); 154 151 Tcl_HideCommand(interp, "unknown", "unknown"); 152 + 153 + return(interp); 154 +} 155 + 156 +static Tcl_Interp *appfs_TclInterp(void) { 157 + Tcl_Interp *interp; 158 + 159 + interp = pthread_getspecific(interpKey); 160 + if (interp == NULL) { 161 + interp = appfs_create_TclInterp(); 162 + 163 + if (interp == NULL) { 164 + return(NULL); 165 + } 166 + 167 + pthread_setspecific(interpKey, interp); 168 + } 155 169 156 170 return(interp); 157 171 } 158 172 159 173 static int appfs_Tcl_Eval(Tcl_Interp *interp, int objc, const char *cmd, ...) { 160 174 Tcl_Obj **objv; 161 175 const char *arg; ................................................................................ 196 210 197 211 static void appfs_update_index(const char *hostname) { 198 212 Tcl_Interp *interp; 199 213 int tcl_ret; 200 214 201 215 APPFS_DEBUG("Enter: hostname = %s", hostname); 202 216 203 - interp = pthread_getspecific(interpKey); 217 + interp = appfs_TclInterp(); 204 218 if (interp == NULL) { 205 - interp = appfs_create_TclInterp(); 206 - 207 - if (interp == NULL) { 208 - return; 209 - } 210 - 211 - pthread_setspecific(interpKey, interp); 219 + return; 212 220 } 213 221 214 222 tcl_ret = appfs_Tcl_Eval(interp, 2, "::appfs::getindex", hostname); 215 223 if (tcl_ret != TCL_OK) { 216 224 APPFS_DEBUG("Call to ::appfs::getindex failed: %s", Tcl_GetStringResult(interp)); 217 225 218 226 return; ................................................................................ 222 230 } 223 231 224 232 static const char *appfs_getfile(const char *hostname, const char *sha1) { 225 233 Tcl_Interp *interp; 226 234 char *retval; 227 235 int tcl_ret; 228 236 229 - interp = pthread_getspecific(interpKey); 237 + interp = appfs_TclInterp(); 230 238 if (interp == NULL) { 231 - interp = appfs_create_TclInterp(); 232 - 233 - if (interp == NULL) { 234 - return(NULL); 235 - } 236 - 237 - pthread_setspecific(interpKey, interp); 239 + return(NULL); 238 240 } 239 241 240 242 tcl_ret = appfs_Tcl_Eval(interp, 3, "::appfs::download", hostname, sha1); 241 243 if (tcl_ret != TCL_OK) { 242 244 APPFS_DEBUG("Call to ::appfs::download failed: %s", Tcl_GetStringResult(interp)); 243 245 244 246 return(NULL); ................................................................................ 249 251 return(retval); 250 252 } 251 253 252 254 static void appfs_update_manifest(const char *hostname, const char *sha1) { 253 255 Tcl_Interp *interp; 254 256 int tcl_ret; 255 257 256 - interp = pthread_getspecific(interpKey); 258 + interp = appfs_TclInterp(); 257 259 if (interp == NULL) { 258 - interp = appfs_create_TclInterp(); 259 - 260 - if (interp == NULL) { 261 - return; 262 - } 263 - 264 - pthread_setspecific(interpKey, interp); 260 + return; 265 261 } 266 262 267 263 tcl_ret = appfs_Tcl_Eval(interp, 3, "::appfs::getpkgmanifest", hostname, sha1); 268 264 if (tcl_ret != TCL_OK) { 269 265 APPFS_DEBUG("Call to ::appfs::getpkgmanifest failed: %s", Tcl_GetStringResult(interp)); 270 266 271 267 return; ................................................................................ 275 271 } 276 272 277 273 static uid_t appfs_get_fsuid(void) { 278 274 struct fuse_context *ctx; 279 275 280 276 ctx = fuse_get_context(); 281 277 if (ctx == NULL) { 278 + /* Unable to lookup user for some reason */ 279 + /* Return an unprivileged user ID */ 282 280 return(1); 283 281 } 284 282 285 283 return(ctx->uid); 286 284 } 287 285 288 286 static char *appfs_get_homedir(uid_t fsuid) { ................................................................................ 349 347 Tcl_SetObjResult(interp, Tcl_NewStringObj(homedir, -1)); 350 348 351 349 free(homedir); 352 350 353 351 return(TCL_OK); 354 352 } 355 353 356 -static struct appfs_children *appfs_getchildren(const char *hostname, const char *package_hash, const char *path, int *children_count_p) { 357 -} 358 - 359 -static char *appfs_lookup_package_hash(const char *hostname, const char *package, const char *os, const char *cpuArch, const char *version) { 360 -} 361 - 362 -static int appfs_getfileinfo(const char *hostname, const char *package_hash, const char *_path, struct appfs_pathinfo *pathinfo) { 363 -} 364 - 365 354 /* Generate an inode for a given path */ 366 355 static long long appfs_get_path_inode(const char *path) { 367 356 long long retval; 368 357 const char *p; 369 358 370 359 retval = 10; 371 360 ................................................................................ 575 564 576 565 if (tcl_ret != TCL_OK) { 577 566 fprintf(stderr, "[error] %s\n", sql_ret); 578 567 579 568 return(1); 580 569 } 581 570 582 - printf("%s\n", sql_ret); 571 + if (sql_ret && sql_ret[0] != '\0') { 572 + printf("%s\n", sql_ret); 573 + } 574 + 575 + return(0); 576 +} 577 + 578 +static int appfs_tcl(const char *tcl) { 579 + Tcl_Interp *interp; 580 + const char *tcl_result; 581 + int tcl_ret; 582 + 583 + interp = appfs_create_TclInterp(); 584 + if (interp == NULL) { 585 + fprintf(stderr, "Unable to create a Tcl interpreter. Aborting.\n"); 586 + 587 + return(1); 588 + } 589 + 590 + tcl_ret = Tcl_Eval(interp, tcl); 591 + tcl_result = Tcl_GetStringResult(interp); 592 + 593 + if (tcl_ret != TCL_OK) { 594 + fprintf(stderr, "[error] %s\n", tcl_result); 595 + 596 + return(1); 597 + } 598 + 599 + if (tcl_result && tcl_result[0] != '\0') { 600 + printf("%s\n", tcl_result); 601 + } 583 602 584 603 return(0); 585 604 } 586 605 587 606 static int Appfsd_Init(Tcl_Interp *interp) { 588 607 #ifdef USE_TCL_STUBS 589 608 if (Tcl_InitStubs(interp, TCL_VERSION, 0) == 0L) { ................................................................................ 624 643 625 644 return(1); 626 645 } 627 646 628 647 if (argc == 3 && strcmp(argv[1], "-sqlite3") == 0) { 629 648 return(appfs_sqlite3(argv[2])); 630 649 } 650 + 651 + if (argc == 3 && strcmp(argv[1], "-tcl") == 0) { 652 + return(appfs_tcl(argv[2])); 653 + } 631 654 632 655 return(fuse_main(argc, argv, &appfs_oper, NULL)); 633 656 } 634 657