Chromium Code Reviews| Index: src/untrusted/irt/irt_manifest.c |
| =================================================================== |
| --- src/untrusted/irt/irt_manifest.c (revision 0) |
| +++ src/untrusted/irt/irt_manifest.c (revision 0) |
| @@ -0,0 +1,79 @@ |
| +#include <string.h> |
| +#include <stdio.h> |
| +#include <sys/nacl_syscalls.h> |
| +#include <nacl/nacl_srpc.h> |
| +#include <sys/nacl_name_service.h> |
| +#include <sys/fcntl.h> |
| +#include "native_client/src/untrusted/irt/irt.h" |
| + |
| +static void print_error(const char *message) { |
| + write(2, message, strlen(message)); |
| +} |
| + |
| +int irt_open_file_in_manifest (const char* file) { |
| + int ns; |
| + int connected_socket; |
| + struct NaClSrpcChannel ns_channel; |
| + int status; |
| + int desc; |
| + int manifest; |
| + int manifest_conn; |
| + struct NaClSrpcChannel manifest_channel; |
| + print_error("irt here\n"); |
| + ns = -1; |
| + nacl_nameservice(&ns); |
| + printf("irt ns = %d\n", ns); |
| + if (-1 == ns) { |
| + print_error("Can't connect to name service\n"); |
| + return -1; |
| + } |
| + connected_socket = imc_connect(ns); |
| + if (-1 == connected_socket) { |
| + print_error("Can't connect to name service\n"); |
| + return -1; |
| + } |
| + close(ns); |
| + if (!NaClSrpcClientCtor(&ns_channel, connected_socket)) { |
| + print_error("Srpc client channel ctor failed\n"); |
| + return -1; |
| + } |
| + if (NACL_SRPC_RESULT_OK != NaClSrpcInvokeBySignature( |
| + &ns_channel, NACL_NAME_SERVICE_LOOKUP, "ManifestNameService", O_RDWR, |
| + &status, &manifest)) { |
| + print_error("Nameservice lookup failed, status\n"); |
| + NaClSrpcDtor(&ns_channel); |
| + return -1; |
| + } |
| + if (-1 == manifest) { |
| + print_error("Manifest descriptor is invalid\n"); |
| + NaClSrpcDtor(&ns_channel); |
| + return -1; |
| + } |
| + manifest_conn = imc_connect(manifest); |
| + if (-1 == manifest_conn) { |
| + print_error("Can't connect to manifest service\n"); |
| + NaClSrpcDtor(&ns_channel); |
| + return -1; |
| + } |
| + close(manifest); |
| + if (!NaClSrpcClientCtor(&manifest_channel, manifest_conn)) { |
| + print_error("Can't create manifest srpc channel\n"); |
| + NaClSrpcDtor(&ns_channel); |
| + return -1; |
| + } |
| + desc = 0; |
| + if (NACL_SRPC_RESULT_OK != NaClSrpcInvokeBySignature( |
| + &manifest_channel, NACL_NAME_SERVICE_LOOKUP, file, O_RDONLY, |
| + &status, &desc)) { |
| + print_error("Manifest lookup RPC failed\n"); |
| + NaClSrpcDtor(&manifest_channel); |
| + return -1; |
| + } |
| + NaClSrpcDtor(&manifest_channel); |
|
bsy
2011/08/11 02:32:43
the irt should be able to cache these channels for
halyavin
2011/08/12 08:52:07
Done.
|
| + NaClSrpcDtor(&ns_channel); |
| + return desc; |
| +} |
| + |
| +const struct nacl_irt_manifest_open nacl_irt_manifest_open = { |
| + irt_open_file_in_manifest |
| +}; |