1 /*
2 * Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2006 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * Copyright (c) 2014 Los Alamos National Security, LLC. All rights
13 * reserved.
14 * $COPYRIGHT$
15 *
16 * Additional copyrights may follow
17 *
18 * $HEADER$
19 *
20 * These symbols are in a file by themselves to provide nice linker
21 * semantics. Since linkers generally pull in symbols by object
22 * files, keeping these symbols as the only symbols in this file
23 * prevents utility programs such as "ompi_info" from having to import
24 * entire components just to query their version and parameters.
25 */
26
27 #include "opal/types.h"
28
29 #include "orte_config.h"
30 #include "orte/constants.h"
31 #include "orte/mca/common/alps/common_alps.h"
32
33 #include <stdio.h>
34 #include <unistd.h>
35 #include <sys/syscall.h>
36
37
38 /*
39 * determine whether or not calling process is in a Cray PAGG container
40 */
41
42 int orte_common_alps_proc_in_pagg(bool *flag)
43 {
44 int rc = ORTE_SUCCESS;
45 const char proc_job_file[]="/proc/job";
46 FILE *fd = NULL, *fd_task_is_app = NULL;
47 char task_is_app_fname[PATH_MAX];
48
49 if (flag == NULL) {
50 return ORTE_ERR_BAD_PARAM;
51 }
52
53 fd = fopen(proc_job_file, "r");
54 if (fd == NULL) {
55 *flag = 0;
56 } else {
57 snprintf(task_is_app_fname,sizeof(task_is_app_fname),
58 "/proc/self/task/%ld/task_is_app",syscall(SYS_gettid));
59 fd_task_is_app = fopen(task_is_app_fname, "r");
60 if (fd_task_is_app != NULL) { /* okay we're in a PAGG container,
61 and we are an app task (not just a process
62 running on a mom node, for example), */
63 *flag = 1;
64 fclose(fd_task_is_app);
65 } else {
66 *flag = 0;
67 }
68 fclose(fd);
69 }
70
71 return rc;
72 }
73