2013-12-12 16:21:55 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* fs/procfs/fs_procfsproc.c
|
|
|
|
*
|
2020-05-09 17:05:29 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you 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
|
2013-12-12 16:21:55 +01:00
|
|
|
*
|
2020-05-09 17:05:29 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-12-12 16:21:55 +01:00
|
|
|
*
|
2020-05-09 17:05:29 +02:00
|
|
|
* 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.
|
2013-12-12 16:21:55 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2020-11-13 06:49:23 +01:00
|
|
|
#include <inttypes.h>
|
2013-12-12 16:21:55 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
2022-01-22 13:21:51 +01:00
|
|
|
#include <malloc.h>
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2018-11-24 17:32:45 +01:00
|
|
|
#ifdef CONFIG_SCHED_CRITMONITOR
|
|
|
|
# include <time.h>
|
|
|
|
#endif
|
|
|
|
|
2016-02-14 15:43:47 +01:00
|
|
|
#include <nuttx/irq.h>
|
2022-05-27 04:05:43 +02:00
|
|
|
#include <nuttx/tls.h>
|
2013-12-12 16:21:55 +01:00
|
|
|
#include <nuttx/sched.h>
|
|
|
|
#include <nuttx/kmalloc.h>
|
2018-08-10 18:16:39 +02:00
|
|
|
#include <nuttx/environ.h>
|
2023-03-23 21:36:14 +01:00
|
|
|
#include <nuttx/signal.h>
|
2013-12-12 16:21:55 +01:00
|
|
|
#include <nuttx/fs/fs.h>
|
|
|
|
#include <nuttx/fs/procfs.h>
|
2022-02-16 08:47:57 +01:00
|
|
|
#include <nuttx/fs/ioctl.h>
|
2022-01-22 13:21:51 +01:00
|
|
|
#include <nuttx/mm/mm.h>
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2018-11-24 17:32:45 +01:00
|
|
|
#if defined(CONFIG_SCHED_CPULOAD) || defined(CONFIG_SCHED_CRITMONITOR)
|
2014-02-23 17:55:01 +01:00
|
|
|
# include <nuttx/clock.h>
|
|
|
|
#endif
|
|
|
|
|
2013-12-12 16:21:55 +01:00
|
|
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS)
|
|
|
|
#ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
2019-03-01 22:00:00 +01:00
|
|
|
|
2014-02-22 22:20:12 +01:00
|
|
|
/* Determines the size of an intermediate buffer that must be large enough
|
2013-12-14 17:34:08 +01:00
|
|
|
* to handle the longest line generated by this logic.
|
|
|
|
*/
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2022-02-16 08:47:57 +01:00
|
|
|
#define STATUS_LINELEN PATH_MAX
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-07-23 17:58:41 +02:00
|
|
|
* Private Type Definitions
|
2013-12-12 16:21:55 +01:00
|
|
|
****************************************************************************/
|
2018-08-10 18:16:39 +02:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* This enumeration identifies all of the task/thread nodes that can be
|
2013-12-12 16:21:55 +01:00
|
|
|
* accessed via the procfs file system.
|
|
|
|
*/
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
enum proc_node_e
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
PROC_LEVEL0 = 0, /* The top-level directory */
|
|
|
|
PROC_STATUS, /* Task/thread status */
|
2013-12-15 21:35:47 +01:00
|
|
|
PROC_CMDLINE, /* Task command line */
|
2014-02-23 17:55:01 +01:00
|
|
|
#ifdef CONFIG_SCHED_CPULOAD
|
|
|
|
PROC_LOADAVG, /* Average CPU utilization */
|
2018-11-24 17:32:45 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_CRITMONITOR
|
|
|
|
PROC_CRITMON, /* Critical section monitor */
|
2022-01-22 13:21:51 +01:00
|
|
|
#endif
|
2022-07-04 09:41:06 +02:00
|
|
|
#if CONFIG_MM_BACKTRACE >= 0
|
2022-01-22 13:21:51 +01:00
|
|
|
PROC_HEAP, /* Task heap info */
|
2022-04-29 08:10:11 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_DEBUG_MM
|
|
|
|
PROC_HEAP_CHECK, /* Task heap check flag */
|
2014-02-23 17:55:01 +01:00
|
|
|
#endif
|
2013-12-15 21:35:47 +01:00
|
|
|
PROC_STACK, /* Task stack info */
|
2013-12-15 17:31:07 +01:00
|
|
|
PROC_GROUP, /* Group directory */
|
|
|
|
PROC_GROUP_STATUS, /* Task group status */
|
|
|
|
PROC_GROUP_FD /* Group file descriptors */
|
2018-08-19 14:36:23 +02:00
|
|
|
#if !defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_FS_PROCFS_EXCLUDE_ENVIRON)
|
2018-08-10 18:16:39 +02:00
|
|
|
, PROC_GROUP_ENV /* Group environment variables */
|
|
|
|
#endif
|
2013-12-12 16:21:55 +01:00
|
|
|
};
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* This structure associates a relative path name with an node in the task
|
|
|
|
* procfs
|
|
|
|
*/
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
struct proc_node_s
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
FAR const char *relpath; /* Relative path to the node */
|
|
|
|
FAR const char *name; /* Terminal node segment name */
|
|
|
|
uint8_t node; /* Type of node (see enum proc_node_e) */
|
|
|
|
uint8_t dtype; /* dirent type (see include/dirent.h) */
|
2013-12-12 16:21:55 +01:00
|
|
|
};
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* This structure describes one open "file" */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
struct proc_file_s
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
struct procfs_file_s base; /* Base open file structure */
|
|
|
|
FAR const struct proc_node_s *node; /* Describes the file node */
|
|
|
|
pid_t pid; /* Task/thread ID */
|
|
|
|
char line[STATUS_LINELEN]; /* Pre-allocated buffer for formatted lines */
|
2013-12-12 16:21:55 +01:00
|
|
|
};
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* This structure describes one open "directory" */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
struct proc_dir_s
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2015-11-27 19:33:58 +01:00
|
|
|
struct procfs_dir_priv_s base; /* Base directory private data */
|
2013-12-15 17:31:07 +01:00
|
|
|
FAR const struct proc_node_s *node; /* Directory node description */
|
2015-11-27 19:33:58 +01:00
|
|
|
pid_t pid; /* ID of task/thread for attributes */
|
2013-12-12 16:21:55 +01:00
|
|
|
};
|
|
|
|
|
2018-08-10 18:16:39 +02:00
|
|
|
/* This structure used with the env_foreach() callback */
|
|
|
|
|
|
|
|
struct proc_envinfo_s
|
|
|
|
{
|
|
|
|
FAR struct proc_file_s *procfile;
|
|
|
|
FAR char *buffer;
|
|
|
|
FAR off_t offset;
|
|
|
|
size_t buflen;
|
|
|
|
size_t remaining;
|
|
|
|
size_t totalsize;
|
|
|
|
};
|
|
|
|
|
2015-07-23 17:58:41 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static FAR const char *g_policy[4] =
|
|
|
|
{
|
2023-01-30 16:19:08 +01:00
|
|
|
"SCHED_FIFO", "SCHED_RR", "SCHED_SPORADIC"
|
2015-07-23 17:58:41 +02:00
|
|
|
};
|
|
|
|
|
2013-12-12 16:21:55 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
2018-11-24 17:32:45 +01:00
|
|
|
|
2013-12-12 16:21:55 +01:00
|
|
|
/* Helpers */
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
static FAR const struct proc_node_s *
|
|
|
|
proc_findnode(FAR const char *relpath);
|
|
|
|
static ssize_t proc_status(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer, size_t buflen,
|
|
|
|
off_t offset);
|
|
|
|
static ssize_t proc_cmdline(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer, size_t buflen,
|
|
|
|
off_t offset);
|
2014-02-23 17:55:01 +01:00
|
|
|
#ifdef CONFIG_SCHED_CPULOAD
|
|
|
|
static ssize_t proc_loadavg(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer, size_t buflen,
|
|
|
|
off_t offset);
|
|
|
|
#endif
|
2018-11-24 17:32:45 +01:00
|
|
|
#ifdef CONFIG_SCHED_CRITMONITOR
|
|
|
|
static ssize_t proc_critmon(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer, size_t buflen,
|
|
|
|
off_t offset);
|
|
|
|
#endif
|
2022-07-04 09:41:06 +02:00
|
|
|
#if CONFIG_MM_BACKTRACE >= 0
|
2022-01-22 13:21:51 +01:00
|
|
|
static ssize_t proc_heap(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer,
|
|
|
|
size_t buflen, off_t offset);
|
|
|
|
#endif
|
2022-04-29 08:10:11 +02:00
|
|
|
#ifdef CONFIG_DEBUG_MM
|
|
|
|
static ssize_t proc_heapcheck(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer,
|
|
|
|
size_t buflen, off_t offset);
|
|
|
|
static ssize_t proc_heapcheck_write(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR const char *buffer,
|
|
|
|
size_t buflen, off_t offset);
|
|
|
|
#endif
|
2013-12-15 21:35:47 +01:00
|
|
|
static ssize_t proc_stack(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer, size_t buflen,
|
|
|
|
off_t offset);
|
2013-12-15 17:31:07 +01:00
|
|
|
static ssize_t proc_groupstatus(FAR struct proc_file_s *procfile,
|
2013-12-12 16:21:55 +01:00
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer, size_t buflen,
|
|
|
|
off_t offset);
|
2013-12-15 17:31:07 +01:00
|
|
|
static ssize_t proc_groupfd(FAR struct proc_file_s *procfile,
|
2013-12-12 16:21:55 +01:00
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer, size_t buflen,
|
|
|
|
off_t offset);
|
2018-08-19 14:36:23 +02:00
|
|
|
#if !defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_FS_PROCFS_EXCLUDE_ENVIRON)
|
2018-08-10 18:16:39 +02:00
|
|
|
static int proc_groupenv_callback(FAR void *arg, FAR const char *pair);
|
|
|
|
static ssize_t proc_groupenv(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer, size_t buflen,
|
|
|
|
off_t offset);
|
|
|
|
#endif
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
/* File system methods */
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
static int proc_open(FAR struct file *filep, FAR const char *relpath,
|
2013-12-12 16:21:55 +01:00
|
|
|
int oflags, mode_t mode);
|
2013-12-15 17:31:07 +01:00
|
|
|
static int proc_close(FAR struct file *filep);
|
|
|
|
static ssize_t proc_read(FAR struct file *filep, FAR char *buffer,
|
2013-12-12 16:21:55 +01:00
|
|
|
size_t buflen);
|
2022-04-29 08:10:11 +02:00
|
|
|
static ssize_t proc_write(FAR struct file *filep, FAR const char *buffer,
|
|
|
|
size_t buflen);
|
2013-12-15 17:31:07 +01:00
|
|
|
static int proc_dup(FAR const struct file *oldp,
|
2013-12-12 16:21:55 +01:00
|
|
|
FAR struct file *newp);
|
|
|
|
|
2020-05-09 17:05:29 +02:00
|
|
|
static int proc_opendir(const char *relpath,
|
2022-08-05 06:31:25 +02:00
|
|
|
FAR struct fs_dirent_s **dir);
|
2013-12-15 17:31:07 +01:00
|
|
|
static int proc_closedir(FAR struct fs_dirent_s *dir);
|
2022-07-26 08:56:41 +02:00
|
|
|
static int proc_readdir(FAR struct fs_dirent_s *dir,
|
|
|
|
FAR struct dirent *entry);
|
2013-12-15 17:31:07 +01:00
|
|
|
static int proc_rewinddir(FAR struct fs_dirent_s *dir);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
static int proc_stat(FAR const char *relpath, FAR struct stat *buf);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2016-02-22 01:08:58 +01:00
|
|
|
* Private Data
|
2013-12-12 16:21:55 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-10-03 00:30:35 +02:00
|
|
|
* Public Data
|
2013-12-12 16:21:55 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* See fs_mount.c -- this structure is explicitly externed there.
|
|
|
|
* We use the old-fashioned kind of initializers so that this will compile
|
|
|
|
* with any compiler.
|
|
|
|
*/
|
|
|
|
|
2023-04-17 20:23:18 +02:00
|
|
|
const struct procfs_operations g_proc_operations =
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
proc_open, /* open */
|
|
|
|
proc_close, /* close */
|
|
|
|
proc_read, /* read */
|
2022-04-29 08:10:11 +02:00
|
|
|
proc_write, /* write */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
proc_dup, /* dup */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
proc_opendir, /* opendir */
|
|
|
|
proc_closedir, /* closedir */
|
|
|
|
proc_readdir, /* readdir */
|
|
|
|
proc_rewinddir, /* rewinddir */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
proc_stat /* stat */
|
2013-12-12 16:21:55 +01:00
|
|
|
};
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* These structures provide information about every node */
|
|
|
|
|
|
|
|
static const struct proc_node_s g_level0node =
|
|
|
|
{
|
|
|
|
"", "", (uint8_t)PROC_LEVEL0, DTYPE_DIRECTORY /* Top-level directory */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct proc_node_s g_status =
|
|
|
|
{
|
|
|
|
"status", "status", (uint8_t)PROC_STATUS, DTYPE_FILE /* Task/thread status */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct proc_node_s g_cmdline =
|
|
|
|
{
|
2013-12-15 21:35:47 +01:00
|
|
|
"cmdline", "cmdline", (uint8_t)PROC_CMDLINE, DTYPE_FILE /* Task command line */
|
|
|
|
};
|
|
|
|
|
2014-02-23 17:55:01 +01:00
|
|
|
#ifdef CONFIG_SCHED_CPULOAD
|
|
|
|
static const struct proc_node_s g_loadavg =
|
|
|
|
{
|
|
|
|
"loadavg", "loadavg", (uint8_t)PROC_LOADAVG, DTYPE_FILE /* Average CPU utilization */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-11-24 17:32:45 +01:00
|
|
|
#ifdef CONFIG_SCHED_CRITMONITOR
|
|
|
|
static const struct proc_node_s g_critmon =
|
|
|
|
{
|
|
|
|
"critmon", "critmon", (uint8_t)PROC_CRITMON, DTYPE_FILE /* Critical Section Monitor */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2022-07-04 09:41:06 +02:00
|
|
|
#if CONFIG_MM_BACKTRACE >= 0
|
2022-01-22 13:21:51 +01:00
|
|
|
static const struct proc_node_s g_heap =
|
|
|
|
{
|
|
|
|
"heap", "heap", (uint8_t)PROC_HEAP, DTYPE_FILE /* Task heap info */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2022-04-29 08:10:11 +02:00
|
|
|
#ifdef CONFIG_DEBUG_MM
|
|
|
|
static const struct proc_node_s g_heapcheck =
|
|
|
|
{
|
|
|
|
"heapcheck", "heapcheck", (uint8_t)PROC_HEAP_CHECK, DTYPE_FILE /* Task heap info */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2013-12-15 21:35:47 +01:00
|
|
|
static const struct proc_node_s g_stack =
|
|
|
|
{
|
|
|
|
"stack", "stack", (uint8_t)PROC_STACK, DTYPE_FILE /* Task stack info */
|
2013-12-15 17:31:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct proc_node_s g_group =
|
|
|
|
{
|
|
|
|
"group", "group", (uint8_t)PROC_GROUP, DTYPE_DIRECTORY /* Group directory */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct proc_node_s g_groupstatus =
|
|
|
|
{
|
|
|
|
"group/status", "status", (uint8_t)PROC_GROUP_STATUS, DTYPE_FILE /* Task group status */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct proc_node_s g_groupfd =
|
|
|
|
{
|
|
|
|
"group/fd", "fd", (uint8_t)PROC_GROUP_FD, DTYPE_FILE /* Group file descriptors */
|
|
|
|
};
|
|
|
|
|
2018-08-19 14:36:23 +02:00
|
|
|
#if !defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_FS_PROCFS_EXCLUDE_ENVIRON)
|
2018-08-10 18:16:39 +02:00
|
|
|
static const struct proc_node_s g_groupenv =
|
|
|
|
{
|
|
|
|
"group/env", "env", (uint8_t)PROC_GROUP_ENV, DTYPE_FILE /* Group environment variables */
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* This is the list of all nodes */
|
|
|
|
|
|
|
|
static FAR const struct proc_node_s * const g_nodeinfo[] =
|
|
|
|
{
|
|
|
|
&g_status, /* Task/thread status */
|
2013-12-15 21:35:47 +01:00
|
|
|
&g_cmdline, /* Task command line */
|
2014-02-23 17:55:01 +01:00
|
|
|
#ifdef CONFIG_SCHED_CPULOAD
|
|
|
|
&g_loadavg, /* Average CPU utilization */
|
2018-11-24 17:32:45 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_CRITMONITOR
|
|
|
|
&g_critmon, /* Critical section Monitor */
|
2022-01-22 13:21:51 +01:00
|
|
|
#endif
|
2022-07-04 09:41:06 +02:00
|
|
|
#if CONFIG_MM_BACKTRACE >= 0
|
2022-01-22 13:21:51 +01:00
|
|
|
&g_heap, /* Task heap info */
|
2022-04-29 08:10:11 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_DEBUG_MM
|
|
|
|
&g_heapcheck, /* Task heap check flag */
|
2014-02-23 17:55:01 +01:00
|
|
|
#endif
|
2013-12-15 21:35:47 +01:00
|
|
|
&g_stack, /* Task stack info */
|
2013-12-15 17:31:07 +01:00
|
|
|
&g_group, /* Group directory */
|
|
|
|
&g_groupstatus, /* Task group status */
|
|
|
|
&g_groupfd /* Group file descriptors */
|
2018-08-19 14:36:23 +02:00
|
|
|
#if !defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_FS_PROCFS_EXCLUDE_ENVIRON)
|
2018-08-10 18:16:39 +02:00
|
|
|
, &g_groupenv /* Group environment variables */
|
|
|
|
#endif
|
2013-12-15 17:31:07 +01:00
|
|
|
};
|
2018-08-10 18:16:39 +02:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
#define PROC_NNODES (sizeof(g_nodeinfo)/sizeof(FAR const struct proc_node_s * const))
|
|
|
|
|
|
|
|
/* This is the list of all level0 nodes */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
static const struct proc_node_s * const g_level0info[] =
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
&g_status, /* Task/thread status */
|
2013-12-15 21:35:47 +01:00
|
|
|
&g_cmdline, /* Task command line */
|
2014-02-23 17:55:01 +01:00
|
|
|
#ifdef CONFIG_SCHED_CPULOAD
|
|
|
|
&g_loadavg, /* Average CPU utilization */
|
2018-11-24 17:32:45 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_CRITMONITOR
|
|
|
|
&g_critmon, /* Critical section monitor */
|
2022-01-22 13:21:51 +01:00
|
|
|
#endif
|
2022-07-04 09:41:06 +02:00
|
|
|
#if CONFIG_MM_BACKTRACE >= 0
|
2022-01-22 13:21:51 +01:00
|
|
|
&g_heap, /* Task heap info */
|
2022-04-29 08:10:11 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_DEBUG_MM
|
|
|
|
&g_heapcheck, /* Task heap check flag */
|
2014-02-23 17:55:01 +01:00
|
|
|
#endif
|
2013-12-15 21:35:47 +01:00
|
|
|
&g_stack, /* Task stack info */
|
2013-12-15 17:31:07 +01:00
|
|
|
&g_group, /* Group directory */
|
2013-12-12 16:21:55 +01:00
|
|
|
};
|
2013-12-15 17:31:07 +01:00
|
|
|
#define PROC_NLEVEL0NODES (sizeof(g_level0info)/sizeof(FAR const struct proc_node_s * const))
|
|
|
|
|
|
|
|
/* This is the list of all group sub-directory nodes */
|
|
|
|
|
2016-03-21 22:24:15 +01:00
|
|
|
static FAR const struct proc_node_s * const g_groupinfo[] =
|
2013-12-15 17:31:07 +01:00
|
|
|
{
|
|
|
|
&g_groupstatus, /* Task group status */
|
|
|
|
&g_groupfd /* Group file descriptors */
|
2018-08-19 14:36:23 +02:00
|
|
|
#if !defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_FS_PROCFS_EXCLUDE_ENVIRON)
|
2018-08-10 18:16:39 +02:00
|
|
|
, &g_groupenv /* Group environment variables */
|
|
|
|
#endif
|
2013-12-15 17:31:07 +01:00
|
|
|
};
|
|
|
|
#define PROC_NGROUPNODES (sizeof(g_groupinfo)/sizeof(FAR const struct proc_node_s * const))
|
|
|
|
|
2020-12-07 18:38:32 +01:00
|
|
|
static FAR const char * const g_ttypenames[4] =
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
|
|
|
"Task",
|
|
|
|
"pthread",
|
2015-11-28 21:58:56 +01:00
|
|
|
"Kthread",
|
|
|
|
"Invalid"
|
2013-12-12 16:21:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2013-12-15 17:31:07 +01:00
|
|
|
* Name: proc_findnode
|
2013-12-12 16:21:55 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
static FAR const struct proc_node_s *proc_findnode(FAR const char *relpath)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* Search every string in g_nodeinfo or until a match is found */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
for (i = 0; i < PROC_NNODES; i++)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2020-07-30 20:51:58 +02:00
|
|
|
size_t len = strlen(g_nodeinfo[i]->relpath);
|
|
|
|
|
|
|
|
if (strncmp(g_nodeinfo[i]->relpath, relpath, len) == 0 &&
|
|
|
|
(relpath[len] == '\0' || (relpath[len] == '/' &&
|
|
|
|
relpath[len + 1] == '\0' &&
|
|
|
|
g_nodeinfo[i]->dtype == DTYPE_DIRECTORY)))
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
return g_nodeinfo[i];
|
2013-12-12 16:21:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not found */
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
return NULL;
|
2013-12-12 16:21:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2013-12-15 17:31:07 +01:00
|
|
|
* Name: proc_status
|
2015-11-28 21:58:56 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Format:
|
|
|
|
*
|
|
|
|
* 111111111122222222223
|
|
|
|
* 123456789012345678901234567890
|
2019-10-27 18:48:14 +01:00
|
|
|
* Name: xxxx... Task/thread name (See
|
|
|
|
* CONFIG_TASK_NAME_SIZE)
|
2015-11-28 21:58:56 +01:00
|
|
|
* Type: xxxxxxx {Task, pthread, Kthread, Invalid}
|
2015-11-30 13:58:06 +01:00
|
|
|
* PPID: xxxxx Parent thread ID
|
|
|
|
* Group: xxxxx Group ID
|
2016-02-19 22:34:36 +01:00
|
|
|
* CPU: xxx CPU (CONFIG_SMP only)
|
2019-10-27 18:48:14 +01:00
|
|
|
* State: xxxxxxxx,xxxxxxxxx {Invalid, Waiting, Ready, Running,
|
|
|
|
* Inactive},
|
|
|
|
* {Unlock, Semaphore, Signal, MQ empty,
|
|
|
|
* MQ full}
|
2015-11-28 21:58:56 +01:00
|
|
|
* Flags: xxx N,P,X
|
|
|
|
* Priority: nnn Decimal, 0-255
|
2023-01-30 16:19:08 +01:00
|
|
|
* Scheduler: xxxxxxxxxxxxxx {SCHED_FIFO, SCHED_RR, SCHED_SPORADIC}
|
2015-11-28 21:58:56 +01:00
|
|
|
* Sigmask: nnnnnnnn Hexadecimal, 32-bit
|
|
|
|
*
|
2013-12-12 16:21:55 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
static ssize_t proc_status(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer,
|
|
|
|
size_t buflen, off_t offset)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2015-07-23 17:58:41 +02:00
|
|
|
FAR const char *policy;
|
2013-12-12 16:21:55 +01:00
|
|
|
FAR const char *name;
|
2023-02-17 08:54:57 +01:00
|
|
|
char state[32];
|
2013-12-12 16:21:55 +01:00
|
|
|
size_t remaining;
|
|
|
|
size_t linesize;
|
|
|
|
size_t copysize;
|
|
|
|
size_t totalsize;
|
|
|
|
|
|
|
|
remaining = buflen;
|
|
|
|
totalsize = 0;
|
|
|
|
|
|
|
|
/* Show the task name */
|
|
|
|
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
name = tcb->name;
|
|
|
|
#else
|
|
|
|
name = "<noname>";
|
2013-12-15 18:22:48 +01:00
|
|
|
#endif
|
2021-04-28 11:44:58 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
|
|
|
"%-12s%.18s\n", "Name:", name);
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show the thread type */
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%-12s%s\n",
|
|
|
|
"Type:",
|
|
|
|
g_ttypenames[(tcb->flags & TCB_FLAG_TTYPE_MASK)
|
|
|
|
>> TCB_FLAG_TTYPE_SHIFT]);
|
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
2022-10-18 13:33:34 +02:00
|
|
|
"%-12s%d\n", "Group:",
|
|
|
|
tcb->group ? tcb->group->tg_pid : -1);
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2015-11-30 13:58:06 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
2016-02-19 22:34:36 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
if (tcb->task_state >= FIRST_ASSIGNED_STATE &&
|
|
|
|
tcb->task_state <= LAST_ASSIGNED_STATE)
|
|
|
|
{
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
|
|
|
"%-12s%d\n", "CPU:", tcb->cpu);
|
2016-02-19 22:34:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
|
|
|
"%-12s---\n", "CPU:");
|
2016-02-19 22:34:36 +01:00
|
|
|
}
|
|
|
|
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2016-02-19 22:34:36 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-12-12 16:21:55 +01:00
|
|
|
/* Show the thread state */
|
|
|
|
|
2023-02-17 08:54:57 +01:00
|
|
|
nxsched_get_stateinfo(tcb, state, sizeof(state));
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
2023-02-17 08:54:57 +01:00
|
|
|
"%-12s%s\n", "State:", state);
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
2015-11-28 21:58:56 +01:00
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show task flags */
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
|
|
|
"%-12s%c%c%c\n", "Flags:",
|
|
|
|
tcb->flags & TCB_FLAG_NONCANCELABLE ? 'N' : '-',
|
|
|
|
tcb->flags & TCB_FLAG_CANCEL_PENDING ? 'P' : '-',
|
|
|
|
tcb->flags & TCB_FLAG_EXIT_PROCESSING ? 'P' : '-');
|
2015-11-28 21:58:56 +01:00
|
|
|
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2015-11-28 21:58:56 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
2013-12-12 16:21:55 +01:00
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show the thread priority */
|
|
|
|
|
|
|
|
#ifdef CONFIG_PRIORITY_INHERITANCE
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
|
|
|
"%-12s%d (%d)\n", "Priority:",
|
|
|
|
tcb->sched_priority, tcb->base_priority);
|
2013-12-12 16:21:55 +01:00
|
|
|
#else
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n",
|
|
|
|
"Priority:", tcb->sched_priority);
|
2013-12-12 16:21:55 +01:00
|
|
|
#endif
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
2015-07-23 17:58:41 +02:00
|
|
|
/* Show the scheduler policy */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2020-05-09 17:05:29 +02:00
|
|
|
policy = g_policy[(tcb->flags & TCB_FLAG_POLICY_MASK) >>
|
|
|
|
TCB_FLAG_POLICY_SHIFT];
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%-12s%s\n",
|
|
|
|
"Scheduler:", policy);
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
2020-11-09 12:16:44 +01:00
|
|
|
/* Show the signal mask. Note: sigset_t is uint32_t on NuttX. */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
2023-03-23 21:36:14 +01:00
|
|
|
"%-12s" SIGSET_FMT "\n",
|
|
|
|
"SigMask:", SIGSET_ELEM(&tcb->sigprocmask));
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2013-12-15 17:31:07 +01:00
|
|
|
* Name: proc_cmdline
|
2013-12-12 16:21:55 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
static ssize_t proc_cmdline(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer,
|
|
|
|
size_t buflen, off_t offset)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
|
|
|
FAR const char *name;
|
|
|
|
size_t remaining;
|
|
|
|
size_t linesize;
|
|
|
|
size_t copysize;
|
|
|
|
size_t totalsize;
|
|
|
|
|
|
|
|
remaining = buflen;
|
|
|
|
totalsize = 0;
|
|
|
|
|
|
|
|
/* Show the task name */
|
|
|
|
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
name = tcb->name;
|
|
|
|
#else
|
|
|
|
name = "<noname>";
|
2013-12-15 18:22:48 +01:00
|
|
|
#endif
|
2013-12-12 16:21:55 +01:00
|
|
|
linesize = strlen(name);
|
2013-12-15 17:31:07 +01:00
|
|
|
memcpy(procfile->line, name, linesize);
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
2023-02-16 13:38:47 +01:00
|
|
|
/* Show the task / thread argument list (skipping over the name) */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2023-02-16 13:38:47 +01:00
|
|
|
linesize = group_argvstr(tcb, procfile->line, remaining);
|
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
|
|
|
remaining, &offset);
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "\n");
|
2019-10-27 18:48:14 +01:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
|
|
|
remaining, &offset);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
2014-02-23 17:55:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: proc_loadavg
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_CPULOAD
|
|
|
|
static ssize_t proc_loadavg(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer,
|
|
|
|
size_t buflen, off_t offset)
|
|
|
|
{
|
|
|
|
struct cpuload_s cpuload;
|
|
|
|
uint32_t intpart;
|
|
|
|
uint32_t fracpart;
|
|
|
|
size_t linesize;
|
|
|
|
size_t copysize;
|
|
|
|
|
|
|
|
/* Sample the counts for the thread. clock_cpuload should only fail if
|
|
|
|
* the PID is not valid. This could happen if the thread exited sometime
|
|
|
|
* after the procfs entry was opened.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
clock_cpuload(procfile->pid, &cpuload);
|
2014-02-23 17:55:01 +01:00
|
|
|
|
|
|
|
/* On the simulator, you may hit cpuload.total == 0, but probably never on
|
|
|
|
* real hardware.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (cpuload.total > 0)
|
|
|
|
{
|
|
|
|
uint32_t tmp;
|
|
|
|
|
2014-02-23 19:50:51 +01:00
|
|
|
tmp = (1000 * cpuload.active) / cpuload.total;
|
2014-02-23 17:55:01 +01:00
|
|
|
intpart = tmp / 10;
|
|
|
|
fracpart = tmp - 10 * intpart;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
intpart = 0;
|
|
|
|
fracpart = 0;
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
2022-02-19 15:46:58 +01:00
|
|
|
"%3" PRId32 ".%01" PRId32 "%%\n",
|
2021-04-14 16:37:52 +02:00
|
|
|
intpart, fracpart);
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, buflen,
|
|
|
|
&offset);
|
2014-02-23 17:55:01 +01:00
|
|
|
|
|
|
|
return copysize;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-24 17:32:45 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: proc_critmon
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_CRITMONITOR
|
|
|
|
static ssize_t proc_critmon(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer,
|
|
|
|
size_t buflen, off_t offset)
|
|
|
|
{
|
|
|
|
struct timespec maxtime;
|
2023-04-20 10:45:14 +02:00
|
|
|
struct timespec runtime;
|
2018-11-24 17:32:45 +01:00
|
|
|
size_t remaining;
|
|
|
|
size_t linesize;
|
|
|
|
size_t copysize;
|
|
|
|
size_t totalsize;
|
|
|
|
|
|
|
|
remaining = buflen;
|
|
|
|
totalsize = 0;
|
|
|
|
|
|
|
|
/* Convert the for maximum time pre-emption disabled */
|
|
|
|
|
|
|
|
if (tcb->premp_max > 0)
|
|
|
|
{
|
2022-01-24 19:45:18 +01:00
|
|
|
up_perf_convert(tcb->premp_max, &maxtime);
|
2018-11-24 17:32:45 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
maxtime.tv_sec = 0;
|
|
|
|
maxtime.tv_nsec = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the maximum */
|
|
|
|
|
|
|
|
tcb->premp_max = 0;
|
|
|
|
|
|
|
|
/* Generate output for maximum time pre-emption disabled */
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%lu.%09lu,",
|
|
|
|
(unsigned long)maxtime.tv_sec,
|
|
|
|
(unsigned long)maxtime.tv_nsec);
|
2021-05-07 11:55:24 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
2020-05-09 17:05:29 +02:00
|
|
|
&offset);
|
2018-11-24 17:32:45 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert and generate output for maximum time in a critical section */
|
|
|
|
|
|
|
|
if (tcb->crit_max > 0)
|
|
|
|
{
|
2022-01-24 19:45:18 +01:00
|
|
|
up_perf_convert(tcb->crit_max, &maxtime);
|
2018-11-24 17:32:45 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
maxtime.tv_sec = 0;
|
|
|
|
maxtime.tv_nsec = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the maximum */
|
|
|
|
|
|
|
|
tcb->crit_max = 0;
|
|
|
|
|
|
|
|
/* Generate output for maximum time in a critical section */
|
|
|
|
|
2021-05-07 11:55:24 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%lu.%09lu,",
|
|
|
|
(unsigned long)maxtime.tv_sec,
|
|
|
|
(unsigned long)maxtime.tv_nsec);
|
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert and generate output for maximum time thread running */
|
|
|
|
|
|
|
|
if (tcb->run_max > 0)
|
|
|
|
{
|
2022-01-24 19:45:18 +01:00
|
|
|
up_perf_convert(tcb->run_max, &maxtime);
|
2021-05-07 11:55:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
maxtime.tv_sec = 0;
|
|
|
|
maxtime.tv_nsec = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the maximum */
|
|
|
|
|
|
|
|
tcb->run_max = 0;
|
2023-04-20 10:45:14 +02:00
|
|
|
up_perf_convert(tcb->run_time, &runtime);
|
2021-05-07 11:55:24 +02:00
|
|
|
|
2023-04-20 10:45:14 +02:00
|
|
|
/* Output the maximum time the thread has run and
|
|
|
|
* the total time the thread has run
|
|
|
|
*/
|
2021-05-07 11:55:24 +02:00
|
|
|
|
2023-04-20 10:45:14 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
|
|
|
"%lu.%09lu,%lu.%09lu\n",
|
2021-04-14 16:37:52 +02:00
|
|
|
(unsigned long)maxtime.tv_sec,
|
2023-04-20 10:45:14 +02:00
|
|
|
(unsigned long)maxtime.tv_nsec,
|
|
|
|
(unsigned long)runtime.tv_sec,
|
|
|
|
(unsigned long)(runtime.tv_nsec));
|
2021-05-07 11:55:24 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
2020-05-09 17:05:29 +02:00
|
|
|
&offset);
|
2018-11-24 17:32:45 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-01-22 13:21:51 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: proc_heap
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-07-04 09:41:06 +02:00
|
|
|
#if CONFIG_MM_BACKTRACE >= 0
|
2022-01-22 13:21:51 +01:00
|
|
|
static ssize_t proc_heap(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer,
|
|
|
|
size_t buflen, off_t offset)
|
|
|
|
{
|
|
|
|
size_t remaining = buflen;
|
|
|
|
size_t linesize;
|
|
|
|
size_t copysize;
|
|
|
|
size_t totalsize = 0;
|
|
|
|
struct mallinfo_task info;
|
2023-05-28 13:23:56 +02:00
|
|
|
struct malltask task;
|
2022-01-22 13:21:51 +01:00
|
|
|
|
2023-05-28 13:23:56 +02:00
|
|
|
task.pid = tcb->pid;
|
|
|
|
task.seqmin = 0;
|
|
|
|
task.seqmax = ULONG_MAX;
|
2022-01-22 13:21:51 +01:00
|
|
|
#ifdef CONFIG_MM_KERNEL_HEAP
|
|
|
|
if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL)
|
|
|
|
{
|
2023-05-28 13:23:56 +02:00
|
|
|
info = kmm_mallinfo_task(&task);
|
2022-01-22 13:21:51 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2023-05-28 13:23:56 +02:00
|
|
|
info = mallinfo_task(&task);
|
2022-01-22 13:21:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Show the heap alloc size */
|
|
|
|
|
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
|
|
|
"%-12s%d\n", "AllocSize:", info.uordblks);
|
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show the heap alloc block */
|
|
|
|
|
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
|
|
|
"%-12s%d\n", "AllocBlks:", info.aordblks);
|
|
|
|
totalsize += procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-04-29 08:10:11 +02:00
|
|
|
#ifdef CONFIG_DEBUG_MM
|
|
|
|
static ssize_t proc_heapcheck(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer,
|
|
|
|
size_t buflen, off_t offset)
|
|
|
|
{
|
|
|
|
size_t remaining = buflen;
|
|
|
|
size_t linesize;
|
|
|
|
size_t copysize;
|
|
|
|
size_t totalsize = 0;
|
|
|
|
size_t heapcheck = 0;
|
|
|
|
|
2022-11-12 07:18:25 +01:00
|
|
|
if (tcb->flags & TCB_FLAG_HEAP_CHECK)
|
2022-04-29 08:10:11 +02:00
|
|
|
{
|
|
|
|
heapcheck = 1;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:41:01 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%-12s%zu\n",
|
2022-04-29 08:10:11 +02:00
|
|
|
"HeapCheck:", heapcheck);
|
|
|
|
|
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
|
|
|
totalsize += copysize;
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t proc_heapcheck_write(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb,
|
|
|
|
FAR const char *buffer,
|
|
|
|
size_t buflen, off_t offset)
|
|
|
|
{
|
|
|
|
switch (atoi(buffer))
|
|
|
|
{
|
|
|
|
case 0:
|
2022-11-12 07:18:25 +01:00
|
|
|
tcb->flags &= ~TCB_FLAG_HEAP_CHECK;
|
2022-04-29 08:10:11 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
2022-11-12 07:18:25 +01:00
|
|
|
tcb->flags |= TCB_FLAG_HEAP_CHECK;
|
2022-04-29 08:10:11 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ferr("ERROR: invalid argument\n");
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buflen;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-12-15 21:35:47 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: proc_stack
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t proc_stack(FAR struct proc_file_s *procfile,
|
2014-02-23 17:55:01 +01:00
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer,
|
|
|
|
size_t buflen, off_t offset)
|
2013-12-15 21:35:47 +01:00
|
|
|
{
|
|
|
|
size_t remaining;
|
|
|
|
size_t linesize;
|
|
|
|
size_t copysize;
|
|
|
|
size_t totalsize;
|
|
|
|
|
|
|
|
remaining = buflen;
|
|
|
|
totalsize = 0;
|
|
|
|
|
2021-06-19 11:27:08 +02:00
|
|
|
/* Show the stack alloc address */
|
|
|
|
|
2021-07-12 16:03:23 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%-12s%p\n",
|
2021-06-19 11:27:08 +02:00
|
|
|
"StackAlloc:", tcb->stack_alloc_ptr);
|
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
2013-12-15 21:35:47 +01:00
|
|
|
/* Show the stack base address */
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%-12s%p\n",
|
|
|
|
"StackBase:", tcb->stack_base_ptr);
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2013-12-15 21:35:47 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show the stack size */
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%-12s%ld\n",
|
|
|
|
"StackSize:", (long)tcb->adj_stack_size);
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2013-12-15 21:35:47 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
2015-03-05 13:41:14 +01:00
|
|
|
#ifdef CONFIG_STACK_COLORATION
|
2013-12-15 21:35:47 +01:00
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show the stack size */
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%-12s%ld\n",
|
|
|
|
"StackUsed:", (long)up_check_tcbstack(tcb));
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2013-12-15 21:35:47 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
2013-12-12 16:21:55 +01:00
|
|
|
/****************************************************************************
|
2013-12-15 17:31:07 +01:00
|
|
|
* Name: proc_groupstatus
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t proc_groupstatus(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer,
|
|
|
|
size_t buflen, off_t offset)
|
|
|
|
{
|
2013-12-15 18:22:48 +01:00
|
|
|
FAR struct task_group_s *group = tcb->group;
|
|
|
|
size_t remaining;
|
|
|
|
size_t linesize;
|
|
|
|
size_t copysize;
|
|
|
|
size_t totalsize;
|
|
|
|
#ifdef HAVE_GROUP_MEMBERS
|
|
|
|
int i;
|
|
|
|
#endif
|
|
|
|
|
2018-08-19 02:00:23 +02:00
|
|
|
DEBUGASSERT(group != NULL);
|
2013-12-15 18:22:48 +01:00
|
|
|
|
|
|
|
remaining = buflen;
|
|
|
|
totalsize = 0;
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n",
|
|
|
|
"Main task:", group->tg_pid);
|
2019-10-27 18:48:14 +01:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
|
|
|
remaining, &offset);
|
2021-11-09 09:11:29 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n",
|
|
|
|
"Parent:", group->tg_ppid);
|
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
|
|
|
remaining, &offset);
|
2013-12-15 18:22:48 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
|
|
|
"%-12s0x%02x\n",
|
|
|
|
"Flags:", group->tg_flags);
|
2019-10-27 18:48:14 +01:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
|
|
|
remaining, &offset);
|
2013-12-15 18:22:48 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n",
|
|
|
|
"Members:", group->tg_nmembers);
|
2019-10-27 18:48:14 +01:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
2021-07-12 16:03:23 +02:00
|
|
|
remaining, &offset);
|
2013-12-15 18:22:48 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
#ifdef HAVE_GROUP_MEMBERS
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
|
|
|
"Member IDs:");
|
2019-10-27 18:48:14 +01:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
|
|
|
remaining, &offset);
|
2013-12-15 18:22:48 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < group->tg_nmembers; i++)
|
|
|
|
{
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, " %d",
|
|
|
|
group->tg_members[i]);
|
2019-10-27 18:48:14 +01:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
|
|
|
remaining, &offset);
|
2013-12-15 18:22:48 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "\n");
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2013-12-15 18:22:48 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return totalsize;
|
2013-12-15 17:31:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: proc_groupfd
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t proc_groupfd(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer,
|
|
|
|
size_t buflen, off_t offset)
|
|
|
|
{
|
2013-12-15 18:22:48 +01:00
|
|
|
FAR struct task_group_s *group = tcb->group;
|
|
|
|
FAR struct file *file;
|
2022-02-16 08:47:57 +01:00
|
|
|
char path[PATH_MAX];
|
2013-12-15 18:22:48 +01:00
|
|
|
size_t remaining;
|
|
|
|
size_t linesize;
|
|
|
|
size_t copysize;
|
|
|
|
size_t totalsize;
|
|
|
|
int i;
|
2021-03-16 13:13:02 +01:00
|
|
|
int j;
|
2013-12-15 18:22:48 +01:00
|
|
|
|
2018-08-19 02:00:23 +02:00
|
|
|
DEBUGASSERT(group != NULL);
|
2013-12-15 18:22:48 +01:00
|
|
|
|
|
|
|
remaining = buflen;
|
|
|
|
totalsize = 0;
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
2022-02-16 08:47:57 +01:00
|
|
|
"\n%-3s %-8s %-8s %s\n",
|
|
|
|
"FD", "POS", "OFLAGS", "PATH");
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2013-12-15 18:22:48 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Examine each open file descriptor */
|
|
|
|
|
2021-03-16 13:13:02 +01:00
|
|
|
for (i = 0; i < group->tg_filelist.fl_rows; i++)
|
2013-12-15 18:22:48 +01:00
|
|
|
{
|
2021-03-16 13:13:02 +01:00
|
|
|
for (j = 0, file = group->tg_filelist.fl_files[i];
|
|
|
|
j < CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
|
|
|
|
j++, file++)
|
2013-12-15 18:22:48 +01:00
|
|
|
{
|
2021-03-16 13:13:02 +01:00
|
|
|
/* Is there an inode associated with the file descriptor? */
|
2013-12-15 18:22:48 +01:00
|
|
|
|
2021-03-16 13:13:02 +01:00
|
|
|
if (file->f_inode && !INODE_IS_SOCKET(file->f_inode))
|
2013-12-15 18:22:48 +01:00
|
|
|
{
|
2022-02-16 08:47:57 +01:00
|
|
|
if (file_ioctl(file, FIOC_FILEPATH, path) < 0)
|
|
|
|
{
|
|
|
|
path[0] = '\0';
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
2022-02-16 08:47:57 +01:00
|
|
|
"%3d %8ld %8x",
|
2021-03-16 13:13:02 +01:00
|
|
|
i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK +
|
|
|
|
j, (long)file->f_pos,
|
|
|
|
file->f_oflags);
|
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
|
|
|
remaining, &offset);
|
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
2022-02-16 08:47:57 +01:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
|
|
|
" %s\n", path);
|
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
|
|
|
remaining, &offset);
|
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
2021-03-16 13:13:02 +01:00
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
2013-12-15 18:22:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-11 22:47:25 +01:00
|
|
|
#ifdef CONFIG_NET
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
|
|
|
"\n%-3s %-2s %-3s %s\n",
|
|
|
|
"SD", "RF", "TYP", "FLAGS");
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
|
|
|
&offset);
|
2013-12-15 18:22:48 +01:00
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Examine each open socket descriptor */
|
|
|
|
|
2021-03-16 13:13:02 +01:00
|
|
|
for (i = 0; i < group->tg_filelist.fl_rows; i++)
|
2013-12-15 18:22:48 +01:00
|
|
|
{
|
2021-03-16 13:13:02 +01:00
|
|
|
for (j = 0, file = group->tg_filelist.fl_files[i];
|
|
|
|
j < CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
|
|
|
|
j++, file++)
|
2013-12-15 18:22:48 +01:00
|
|
|
{
|
2021-03-16 13:13:02 +01:00
|
|
|
/* Is there an connection associated with the socket descriptor? */
|
|
|
|
|
|
|
|
if (file->f_inode && INODE_IS_SOCKET(file->f_inode))
|
2013-12-15 18:22:48 +01:00
|
|
|
{
|
2021-03-16 13:13:02 +01:00
|
|
|
FAR struct socket *socket = file->f_priv;
|
2022-02-08 06:18:01 +01:00
|
|
|
FAR struct socket_conn_s *conn = socket->s_conn;
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
2021-03-16 13:13:02 +01:00
|
|
|
"%3d %3d %02x",
|
|
|
|
i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK +
|
2022-02-08 06:18:01 +01:00
|
|
|
j, socket->s_type, conn->s_flags);
|
2021-03-16 13:13:02 +01:00
|
|
|
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
|
|
|
remaining, &offset);
|
|
|
|
|
|
|
|
totalsize += copysize;
|
|
|
|
buffer += copysize;
|
|
|
|
remaining -= copysize;
|
|
|
|
|
|
|
|
if (totalsize >= buflen)
|
|
|
|
{
|
|
|
|
return totalsize;
|
|
|
|
}
|
2013-12-15 18:22:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return totalsize;
|
2013-12-15 17:31:07 +01:00
|
|
|
}
|
|
|
|
|
2018-08-10 18:16:39 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: proc_groupenv_callback
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-08-19 14:36:23 +02:00
|
|
|
#if !defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_FS_PROCFS_EXCLUDE_ENVIRON)
|
2018-08-10 18:16:39 +02:00
|
|
|
static int proc_groupenv_callback(FAR void *arg, FAR const char *pair)
|
|
|
|
{
|
|
|
|
FAR struct proc_envinfo_s *info = (FAR struct proc_envinfo_s *)arg;
|
|
|
|
FAR const char *src;
|
|
|
|
FAR const char *value;
|
|
|
|
FAR char *dest;
|
|
|
|
char name[16 + 1];
|
|
|
|
size_t linesize;
|
|
|
|
size_t copysize;
|
|
|
|
int namelen;
|
|
|
|
|
|
|
|
DEBUGASSERT(arg != NULL && pair != NULL);
|
|
|
|
|
|
|
|
/* Parse the name from the name/value pair */
|
|
|
|
|
|
|
|
value = NULL;
|
|
|
|
namelen = 0;
|
|
|
|
|
|
|
|
for (src = pair, dest = name; *src != '=' && *src != '\0'; src++)
|
|
|
|
{
|
|
|
|
if (namelen < 16)
|
|
|
|
{
|
|
|
|
*dest++ = *src;
|
|
|
|
namelen++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NUL terminate the name string */
|
|
|
|
|
|
|
|
*dest = '\0';
|
|
|
|
|
|
|
|
/* Skip over the '=' to get the value */
|
|
|
|
|
|
|
|
if (*src == '=')
|
|
|
|
{
|
|
|
|
value = src + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Output the header */
|
|
|
|
|
2021-04-14 16:37:52 +02:00
|
|
|
linesize = procfs_snprintf(info->procfile->line,
|
|
|
|
STATUS_LINELEN, "%s=%s\n",
|
|
|
|
name, value);
|
2020-05-09 17:05:29 +02:00
|
|
|
copysize = procfs_memcpy(info->procfile->line, linesize,
|
|
|
|
info->buffer, info->remaining,
|
|
|
|
&info->offset);
|
2018-08-10 18:16:39 +02:00
|
|
|
|
|
|
|
info->totalsize += copysize;
|
|
|
|
info->buffer += copysize;
|
|
|
|
info->remaining -= copysize;
|
|
|
|
|
|
|
|
if (info->totalsize >= info->buflen)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: proc_groupenv
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-08-19 14:36:23 +02:00
|
|
|
#if !defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_FS_PROCFS_EXCLUDE_ENVIRON)
|
2018-08-10 18:16:39 +02:00
|
|
|
static ssize_t proc_groupenv(FAR struct proc_file_s *procfile,
|
|
|
|
FAR struct tcb_s *tcb, FAR char *buffer, size_t buflen,
|
|
|
|
off_t offset)
|
|
|
|
{
|
|
|
|
FAR struct task_group_s *group = tcb->group;
|
|
|
|
struct proc_envinfo_s info;
|
|
|
|
|
2018-08-19 02:00:23 +02:00
|
|
|
DEBUGASSERT(group != NULL);
|
2018-08-10 18:16:39 +02:00
|
|
|
|
|
|
|
/* Initialize the info structure */
|
|
|
|
|
|
|
|
info.procfile = procfile;
|
|
|
|
info.buffer = buffer;
|
|
|
|
info.offset = offset;
|
|
|
|
info.buflen = buflen;
|
|
|
|
info.remaining = buflen;
|
|
|
|
info.totalsize = 0;
|
|
|
|
|
|
|
|
/* Generate output for each environment variable */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
env_foreach(group, proc_groupenv_callback, &info);
|
2018-08-10 18:16:39 +02:00
|
|
|
return info.totalsize;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: proc_open
|
2013-12-12 16:21:55 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
static int proc_open(FAR struct file *filep, FAR const char *relpath,
|
|
|
|
int oflags, mode_t mode)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
FAR struct proc_file_s *procfile;
|
|
|
|
FAR const struct proc_node_s *node;
|
2013-12-12 16:21:55 +01:00
|
|
|
FAR struct tcb_s *tcb;
|
|
|
|
FAR char *ptr;
|
|
|
|
unsigned long tmp;
|
|
|
|
pid_t pid;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Open '%s'\n", relpath);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2018-08-19 02:00:23 +02:00
|
|
|
/* The first segment of the relative path should be a task/thread ID or
|
|
|
|
* the string "self".
|
|
|
|
*/
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
ptr = NULL;
|
|
|
|
|
2018-08-19 02:00:23 +02:00
|
|
|
if (strncmp(relpath, "self", 4) == 0)
|
|
|
|
{
|
2023-02-01 11:05:58 +01:00
|
|
|
tmp = nxsched_gettid(); /* Get the TID of the calling task */
|
2018-08-19 02:00:23 +02:00
|
|
|
ptr = (FAR char *)relpath + 4; /* Discard const */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp = strtoul(relpath, &ptr, 10); /* Extract the PID from path */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr == NULL || *ptr != '/')
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Invalid path \"%s\"\n", relpath);
|
2013-12-12 16:21:55 +01:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip over the slash */
|
|
|
|
|
|
|
|
ptr++;
|
|
|
|
|
2022-03-20 11:12:26 +01:00
|
|
|
/* A valid PID would be in the range of 0-INT_MAX (0 is reserved for the
|
2013-12-12 16:21:55 +01:00
|
|
|
* IDLE thread).
|
|
|
|
*/
|
|
|
|
|
2022-03-20 11:12:26 +01:00
|
|
|
if (tmp > INT_MAX)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Invalid PID %ld\n", tmp);
|
2013-12-12 16:21:55 +01:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now verify that a task with this task/thread ID exists */
|
|
|
|
|
|
|
|
pid = (pid_t)tmp;
|
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
tcb = nxsched_get_tcb(pid);
|
2018-08-19 02:00:23 +02:00
|
|
|
if (tcb == NULL)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2023-06-18 22:20:04 +02:00
|
|
|
ferr("ERROR: PID %d is no longer valid\n", pid);
|
2013-12-12 16:21:55 +01:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* The remaining segments of the relpath should be a well known node in
|
|
|
|
* the task/thread tree.
|
2013-12-12 16:21:55 +01:00
|
|
|
*/
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
node = proc_findnode(ptr);
|
2018-08-19 02:00:23 +02:00
|
|
|
if (node == NULL)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Invalid path \"%s\"\n", relpath);
|
2013-12-12 16:21:55 +01:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* The node must be a file, not a directory */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2015-11-28 15:52:21 +01:00
|
|
|
if (!DIRENT_ISFILE(node->dtype))
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Path \"%s\" is not a regular file\n", relpath);
|
2013-12-15 17:31:07 +01:00
|
|
|
return -EISDIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a container to hold the task and node selection */
|
|
|
|
|
2020-05-09 17:05:29 +02:00
|
|
|
procfile = (FAR struct proc_file_s *)
|
|
|
|
kmm_zalloc(sizeof(struct proc_file_s));
|
2018-08-19 02:00:23 +02:00
|
|
|
if (procfile == NULL)
|
2013-12-15 17:31:07 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Failed to allocate file container\n");
|
2013-12-12 16:21:55 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* Initialize the file container */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
procfile->pid = pid;
|
|
|
|
procfile->node = node;
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
/* Save the index as the open-specific state in filep->f_priv */
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
filep->f_priv = (FAR void *)procfile;
|
2013-12-12 16:21:55 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2013-12-15 17:31:07 +01:00
|
|
|
* Name: proc_close
|
2013-12-12 16:21:55 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
static int proc_close(FAR struct file *filep)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
FAR struct proc_file_s *procfile;
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
/* Recover our private data from the struct file instance */
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
procfile = (FAR struct proc_file_s *)filep->f_priv;
|
2018-08-19 02:00:23 +02:00
|
|
|
DEBUGASSERT(procfile != NULL);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* Release the file container structure */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2014-09-01 01:04:02 +02:00
|
|
|
kmm_free(procfile);
|
2013-12-12 16:21:55 +01:00
|
|
|
filep->f_priv = NULL;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2013-12-15 17:31:07 +01:00
|
|
|
* Name: proc_read
|
2013-12-12 16:21:55 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
static ssize_t proc_read(FAR struct file *filep, FAR char *buffer,
|
|
|
|
size_t buflen)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
FAR struct proc_file_s *procfile;
|
2013-12-12 16:21:55 +01:00
|
|
|
FAR struct tcb_s *tcb;
|
|
|
|
ssize_t ret;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("buffer=%p buflen=%d\n", buffer, (int)buflen);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
/* Recover our private data from the struct file instance */
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
procfile = (FAR struct proc_file_s *)filep->f_priv;
|
2018-08-19 02:00:23 +02:00
|
|
|
DEBUGASSERT(procfile != NULL);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
/* Verify that the thread is still valid */
|
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
tcb = nxsched_get_tcb(procfile->pid);
|
2018-08-19 02:00:23 +02:00
|
|
|
if (tcb == NULL)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2023-06-18 22:20:04 +02:00
|
|
|
ferr("ERROR: PID %d is not valid\n", procfile->pid);
|
2013-12-12 16:21:55 +01:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Provide the requested data */
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
switch (procfile->node->node)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
case PROC_STATUS: /* Task/thread status */
|
|
|
|
ret = proc_status(procfile, tcb, buffer, buflen, filep->f_pos);
|
2013-12-12 16:21:55 +01:00
|
|
|
break;
|
2013-12-15 18:22:48 +01:00
|
|
|
|
2013-12-15 21:35:47 +01:00
|
|
|
case PROC_CMDLINE: /* Task command line */
|
2013-12-15 17:31:07 +01:00
|
|
|
ret = proc_cmdline(procfile, tcb, buffer, buflen, filep->f_pos);
|
|
|
|
break;
|
|
|
|
|
2014-02-23 17:55:01 +01:00
|
|
|
#ifdef CONFIG_SCHED_CPULOAD
|
|
|
|
case PROC_LOADAVG: /* Average CPU utilization */
|
|
|
|
ret = proc_loadavg(procfile, tcb, buffer, buflen, filep->f_pos);
|
|
|
|
break;
|
2018-11-24 17:32:45 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_CRITMONITOR
|
|
|
|
case PROC_CRITMON: /* Critical section monitor */
|
|
|
|
ret = proc_critmon(procfile, tcb, buffer, buflen, filep->f_pos);
|
|
|
|
break;
|
2022-01-22 13:21:51 +01:00
|
|
|
#endif
|
2022-07-04 09:41:06 +02:00
|
|
|
#if CONFIG_MM_BACKTRACE >= 0
|
2022-01-22 13:21:51 +01:00
|
|
|
case PROC_HEAP: /* Task heap info */
|
|
|
|
ret = proc_heap(procfile, tcb, buffer, buflen, filep->f_pos);
|
|
|
|
break;
|
2022-04-29 08:10:11 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_DEBUG_MM
|
|
|
|
case PROC_HEAP_CHECK: /* Task heap check flag */
|
|
|
|
ret = proc_heapcheck(procfile, tcb, buffer, buflen, filep->f_pos);
|
|
|
|
break;
|
2014-02-23 17:55:01 +01:00
|
|
|
#endif
|
2013-12-15 21:35:47 +01:00
|
|
|
case PROC_STACK: /* Task stack info */
|
|
|
|
ret = proc_stack(procfile, tcb, buffer, buflen, filep->f_pos);
|
|
|
|
break;
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
case PROC_GROUP_STATUS: /* Task group status */
|
|
|
|
ret = proc_groupstatus(procfile, tcb, buffer, buflen, filep->f_pos);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROC_GROUP_FD: /* Group file descriptors */
|
|
|
|
ret = proc_groupfd(procfile, tcb, buffer, buflen, filep->f_pos);
|
|
|
|
break;
|
|
|
|
|
2018-08-19 14:36:23 +02:00
|
|
|
#if !defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_FS_PROCFS_EXCLUDE_ENVIRON)
|
2018-08-10 18:16:39 +02:00
|
|
|
case PROC_GROUP_ENV: /* Group environment variables */
|
|
|
|
ret = proc_groupenv(procfile, tcb, buffer, buflen, filep->f_pos);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
2013-12-12 16:21:55 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the file offset */
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
{
|
|
|
|
filep->f_pos += ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-04-29 08:10:11 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: proc_write
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t proc_write(FAR struct file *filep, FAR const char *buffer,
|
|
|
|
size_t buflen)
|
|
|
|
{
|
|
|
|
FAR struct proc_file_s *procfile;
|
|
|
|
FAR struct tcb_s *tcb;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
DEBUGASSERT(filep != NULL && buffer != NULL && buflen > 0);
|
|
|
|
|
|
|
|
procfile = (FAR struct proc_file_s *)filep->f_priv;
|
|
|
|
DEBUGASSERT(procfile != NULL);
|
|
|
|
|
|
|
|
/* Verify that the thread is still valid */
|
|
|
|
|
|
|
|
tcb = nxsched_get_tcb(procfile->pid);
|
|
|
|
if (tcb == NULL)
|
|
|
|
{
|
2023-06-18 22:20:04 +02:00
|
|
|
ferr("ERROR: PID %d is not valid\n", procfile->pid);
|
2022-04-29 08:10:11 +02:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Provide the requested data */
|
|
|
|
|
|
|
|
switch (procfile->node->node)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_DEBUG_MM
|
|
|
|
case PROC_HEAP_CHECK:
|
|
|
|
ret = proc_heapcheck_write(procfile, tcb, buffer, buflen,
|
|
|
|
filep->f_pos);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-12-12 16:21:55 +01:00
|
|
|
/****************************************************************************
|
2013-12-15 17:31:07 +01:00
|
|
|
* Name: proc_dup
|
2013-12-12 16:21:55 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Duplicate open file data in the new file structure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
static int proc_dup(FAR const struct file *oldp, FAR struct file *newp)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
FAR struct proc_file_s *oldfile;
|
|
|
|
FAR struct proc_file_s *newfile;
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Dup %p->%p\n", oldp, newp);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
/* Recover our private data from the old struct file instance */
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
oldfile = (FAR struct proc_file_s *)oldp->f_priv;
|
2018-08-19 02:00:23 +02:00
|
|
|
DEBUGASSERT(oldfile != NULL);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* Allocate a new container to hold the task and node selection */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2014-09-01 01:26:36 +02:00
|
|
|
newfile = (FAR struct proc_file_s *)kmm_malloc(sizeof(struct proc_file_s));
|
2018-08-19 02:00:23 +02:00
|
|
|
if (newfile == NULL)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Failed to allocate file container\n");
|
2013-12-12 16:21:55 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* The copy the file information from the old container to the new */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
memcpy(newfile, oldfile, sizeof(struct proc_file_s));
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* Save the new container in the new file structure */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
newp->f_priv = (FAR void *)newfile;
|
2013-12-12 16:21:55 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2013-12-15 17:31:07 +01:00
|
|
|
* Name: proc_opendir
|
2013-12-12 16:21:55 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Open a directory for read access
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
static int proc_opendir(FAR const char *relpath,
|
|
|
|
FAR struct fs_dirent_s **dir)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
FAR struct proc_dir_s *procdir;
|
|
|
|
FAR const struct proc_node_s *node;
|
2013-12-12 16:21:55 +01:00
|
|
|
FAR struct tcb_s *tcb;
|
2013-12-15 17:31:07 +01:00
|
|
|
unsigned long tmp;
|
|
|
|
FAR char *ptr;
|
|
|
|
pid_t pid;
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("relpath: \"%s\"\n", relpath ? relpath : "NULL");
|
2022-08-05 06:31:25 +02:00
|
|
|
DEBUGASSERT(relpath != NULL);
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* The relative must be either:
|
2013-12-12 16:21:55 +01:00
|
|
|
*
|
2018-08-19 02:00:23 +02:00
|
|
|
* (1) "<pid>" - The sub-directory of task/thread attributes,
|
|
|
|
* (2) "self" - Which refers to the PID of the calling task, or
|
|
|
|
* (3) The name of a directory node under either of those
|
2013-12-12 16:21:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Otherwise, the relative path should be a valid task/thread ID */
|
|
|
|
|
|
|
|
ptr = NULL;
|
|
|
|
|
2018-08-19 02:00:23 +02:00
|
|
|
if (strncmp(relpath, "self", 4) == 0)
|
|
|
|
{
|
2023-02-01 11:05:58 +01:00
|
|
|
tmp = nxsched_gettid(); /* Get the TID of the calling task */
|
2018-08-19 02:00:23 +02:00
|
|
|
ptr = (FAR char *)relpath + 4; /* Discard const */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp = strtoul(relpath, &ptr, 10); /* Extract the PID from path */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr == NULL || (*ptr != '\0' && *ptr != '/'))
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
|
|
|
/* strtoul failed or there is something in the path after the pid */
|
|
|
|
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Invalid path \"%s\"\n", relpath);
|
2013-12-12 16:21:55 +01:00
|
|
|
return -ENOENT;
|
2019-10-27 18:48:14 +01:00
|
|
|
}
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2022-03-20 11:12:26 +01:00
|
|
|
/* A valid PID would be in the range of 0-INT_MAX (0 is reserved for the
|
2013-12-12 16:21:55 +01:00
|
|
|
* IDLE thread).
|
|
|
|
*/
|
|
|
|
|
2022-03-20 11:12:26 +01:00
|
|
|
if (tmp > INT_MAX)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Invalid PID %ld\n", tmp);
|
2013-12-12 16:21:55 +01:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now verify that a task with this task/thread ID exists */
|
|
|
|
|
|
|
|
pid = (pid_t)tmp;
|
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
tcb = nxsched_get_tcb(pid);
|
2018-08-19 02:00:23 +02:00
|
|
|
if (tcb == NULL)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2023-06-18 22:20:04 +02:00
|
|
|
ferr("ERROR: PID %d is not valid\n", pid);
|
2013-12-12 16:21:55 +01:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* Allocate the directory structure. Note that the index and procentry
|
2014-09-01 01:34:44 +02:00
|
|
|
* pointer are implicitly nullified by kmm_zalloc(). Only the remaining,
|
2013-12-15 17:31:07 +01:00
|
|
|
* non-zero entries will need be initialized.
|
|
|
|
*/
|
|
|
|
|
2014-09-01 01:34:44 +02:00
|
|
|
procdir = (FAR struct proc_dir_s *)kmm_zalloc(sizeof(struct proc_dir_s));
|
2018-08-19 02:00:23 +02:00
|
|
|
if (procdir == NULL)
|
2013-12-15 17:31:07 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Failed to allocate the directory structure\n");
|
2013-12-15 17:31:07 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2013-12-12 16:21:55 +01:00
|
|
|
/* Was the <pid> the final element of the path? */
|
|
|
|
|
|
|
|
if (*ptr != '\0' && strcmp(ptr, "/") != 0)
|
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
/* There is something in the path after the pid. Skip over the path
|
|
|
|
* segment delimiter and see if we can identify the node of interest.
|
|
|
|
*/
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
ptr++;
|
|
|
|
node = proc_findnode(ptr);
|
2018-08-19 02:00:23 +02:00
|
|
|
if (node == NULL)
|
2013-12-15 17:31:07 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Invalid path \"%s\"\n", relpath);
|
2014-09-01 01:04:02 +02:00
|
|
|
kmm_free(procdir);
|
2013-12-15 17:31:07 +01:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* The node must be a directory, not a file */
|
|
|
|
|
2015-11-28 15:52:21 +01:00
|
|
|
if (!DIRENT_ISDIRECTORY(node->dtype))
|
2013-12-15 17:31:07 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Path \"%s\" is not a directory\n", relpath);
|
2014-09-01 01:04:02 +02:00
|
|
|
kmm_free(procdir);
|
2013-12-15 17:31:07 +01:00
|
|
|
return -ENOTDIR;
|
|
|
|
}
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* This is a second level directory */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
procdir->base.level = 2;
|
|
|
|
procdir->base.nentries = PROC_NGROUPNODES;
|
|
|
|
procdir->node = node;
|
2013-12-12 16:21:55 +01:00
|
|
|
}
|
2013-12-15 17:31:07 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Use the special level0 node */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
procdir->base.level = 1;
|
|
|
|
procdir->base.nentries = PROC_NLEVEL0NODES;
|
|
|
|
procdir->node = &g_level0node;
|
|
|
|
}
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2019-10-27 18:48:14 +01:00
|
|
|
procdir->pid = pid;
|
2022-08-05 06:31:25 +02:00
|
|
|
*dir = (FAR struct fs_dirent_s *)procdir;
|
2019-10-27 18:48:14 +01:00
|
|
|
return OK;
|
2013-12-12 16:21:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2013-12-15 17:31:07 +01:00
|
|
|
* Name: proc_closedir
|
2013-12-12 16:21:55 +01:00
|
|
|
*
|
|
|
|
* Description: Close the directory listing
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
static int proc_closedir(FAR struct fs_dirent_s *dir)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2022-08-05 06:31:25 +02:00
|
|
|
DEBUGASSERT(dir != NULL);
|
|
|
|
kmm_free(dir);
|
2013-12-12 16:21:55 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2013-12-15 17:31:07 +01:00
|
|
|
* Name: proc_readdir
|
2013-12-12 16:21:55 +01:00
|
|
|
*
|
|
|
|
* Description: Read the next directory entry
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-07-26 08:56:41 +02:00
|
|
|
static int proc_readdir(FAR struct fs_dirent_s *dir,
|
|
|
|
FAR struct dirent *entry)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
FAR struct proc_dir_s *procdir;
|
2014-04-22 18:38:08 +02:00
|
|
|
FAR const struct proc_node_s *node = NULL;
|
2013-12-12 16:21:55 +01:00
|
|
|
FAR struct tcb_s *tcb;
|
|
|
|
unsigned int index;
|
|
|
|
pid_t pid;
|
|
|
|
int ret;
|
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
DEBUGASSERT(dir != NULL);
|
|
|
|
procdir = (FAR struct proc_dir_s *)dir;
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
/* Have we reached the end of the directory */
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
index = procdir->base.index;
|
|
|
|
if (index >= procdir->base.nentries)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
|
|
|
/* We signal the end of the directory by returning the special
|
|
|
|
* error -ENOENT
|
|
|
|
*/
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Entry %d: End of directory\n", index);
|
2013-12-12 16:21:55 +01:00
|
|
|
ret = -ENOENT;
|
|
|
|
}
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* No, we are not at the end of the directory */
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Verify that the pid still refers to an active task/thread */
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
pid = procdir->pid;
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
tcb = nxsched_get_tcb(pid);
|
2018-08-19 02:00:23 +02:00
|
|
|
if (tcb == NULL)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2023-06-18 22:20:04 +02:00
|
|
|
ferr("ERROR: PID %d is no longer valid\n", pid);
|
2013-12-12 16:21:55 +01:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2019-03-01 22:00:00 +01:00
|
|
|
/* The TCB is still valid (or at least was when we entered this
|
|
|
|
* function)
|
|
|
|
*
|
|
|
|
* Handle the directory listing by the node type.
|
|
|
|
*/
|
2013-12-15 17:31:07 +01:00
|
|
|
|
|
|
|
switch (procdir->node->node)
|
|
|
|
{
|
|
|
|
case PROC_LEVEL0: /* Top level directory */
|
|
|
|
DEBUGASSERT(procdir->base.level == 1);
|
|
|
|
node = g_level0info[index];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROC_GROUP: /* Group sub-directory */
|
|
|
|
DEBUGASSERT(procdir->base.level == 2);
|
|
|
|
node = g_groupinfo[index];
|
|
|
|
break;
|
|
|
|
|
2015-03-12 14:42:39 +01:00
|
|
|
default:
|
|
|
|
return -ENOENT;
|
2013-12-15 17:31:07 +01:00
|
|
|
}
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* Save the filename and file type */
|
|
|
|
|
2022-07-26 08:56:41 +02:00
|
|
|
entry->d_type = node->dtype;
|
|
|
|
strlcpy(entry->d_name, node->name, sizeof(entry->d_name));
|
2013-12-12 16:21:55 +01:00
|
|
|
|
|
|
|
/* Set up the next directory entry offset. NOTE that we could use the
|
|
|
|
* standard f_pos instead of our own private index.
|
|
|
|
*/
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
procdir->base.index = index + 1;
|
2013-12-12 16:21:55 +01:00
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2013-12-15 17:31:07 +01:00
|
|
|
* Name: proc_rewindir
|
2013-12-12 16:21:55 +01:00
|
|
|
*
|
|
|
|
* Description: Reset directory read to the first entry
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
static int proc_rewinddir(struct fs_dirent_s *dir)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
FAR struct proc_dir_s *priv;
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
DEBUGASSERT(dir != NULL);
|
|
|
|
priv = (FAR struct proc_dir_s *)dir;
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
priv->base.index = 0;
|
2013-12-12 16:21:55 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2013-12-15 17:31:07 +01:00
|
|
|
* Name: proc_stat
|
2013-12-12 16:21:55 +01:00
|
|
|
*
|
|
|
|
* Description: Return information about a file or directory
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
static int proc_stat(const char *relpath, struct stat *buf)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2013-12-15 17:31:07 +01:00
|
|
|
FAR const struct proc_node_s *node;
|
2013-12-12 16:21:55 +01:00
|
|
|
FAR struct tcb_s *tcb;
|
|
|
|
unsigned long tmp;
|
|
|
|
FAR char *ptr;
|
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
/* Two path forms are accepted:
|
|
|
|
*
|
|
|
|
* "<pid>" - If <pid> refers to a currently active task/thread, then it
|
|
|
|
* is a directory
|
2013-12-15 17:31:07 +01:00
|
|
|
* "<pid>/<node>" - If <node> is a recognized node then, then it
|
|
|
|
* is a file or directory.
|
2013-12-12 16:21:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
ptr = NULL;
|
|
|
|
|
2018-08-19 02:00:23 +02:00
|
|
|
if (strncmp(relpath, "self", 4) == 0)
|
|
|
|
{
|
2023-02-01 11:05:58 +01:00
|
|
|
tmp = nxsched_gettid(); /* Get the TID of the calling task */
|
2018-08-19 02:00:23 +02:00
|
|
|
ptr = (FAR char *)relpath + 4; /* Discard const */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp = strtoul(relpath, &ptr, 10); /* Extract the PID from path */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr == NULL)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Invalid path \"%s\"\n", relpath);
|
2013-12-12 16:21:55 +01:00
|
|
|
return -ENOENT;
|
2019-10-27 18:48:14 +01:00
|
|
|
}
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2022-03-20 11:12:26 +01:00
|
|
|
/* A valid PID would be in the range of 0-INT_MAX (0 is reserved for the
|
2013-12-12 16:21:55 +01:00
|
|
|
* IDLE thread).
|
|
|
|
*/
|
|
|
|
|
2022-03-20 11:12:26 +01:00
|
|
|
if (tmp > INT_MAX)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Invalid PID %ld\n", tmp);
|
2013-12-12 16:21:55 +01:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now verify that a task with this task/thread ID exists */
|
|
|
|
|
|
|
|
pid = (pid_t)tmp;
|
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
tcb = nxsched_get_tcb(pid);
|
2018-08-19 02:00:23 +02:00
|
|
|
if (tcb == NULL)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2023-06-18 22:20:04 +02:00
|
|
|
ferr("ERROR: PID %d is no longer valid\n", pid);
|
2013-12-12 16:21:55 +01:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Was the <pid> the final element of the path? */
|
|
|
|
|
2017-02-15 16:59:09 +01:00
|
|
|
memset(buf, 0, sizeof(struct stat));
|
2013-12-12 16:21:55 +01:00
|
|
|
if (*ptr == '\0' || strcmp(ptr, "/") == 0)
|
|
|
|
{
|
|
|
|
/* Yes ... It's a read-only directory */
|
|
|
|
|
2015-10-11 19:39:29 +02:00
|
|
|
buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR;
|
2013-12-12 16:21:55 +01:00
|
|
|
}
|
2013-12-12 18:08:20 +01:00
|
|
|
|
|
|
|
/* Verify that the process ID is followed by valid path segment delimiter */
|
|
|
|
|
|
|
|
else if (*ptr != '/')
|
|
|
|
{
|
|
|
|
/* We are required to return -ENOENT all all invalid paths */
|
|
|
|
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Bad delimiter '%c' in relpath '%s'\n", *ptr, relpath);
|
2013-12-12 18:08:20 +01:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
2013-12-12 16:21:55 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise, the second segment of the relpath should be a well
|
2013-12-15 17:31:07 +01:00
|
|
|
* known node of the task/thread directory structure.
|
2013-12-12 16:21:55 +01:00
|
|
|
*/
|
|
|
|
|
2013-12-12 18:08:20 +01:00
|
|
|
/* Skip over the path segment delimiter */
|
|
|
|
|
|
|
|
ptr++;
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* Lookup the well-known node associated with the relative path. */
|
2013-12-12 18:08:20 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
node = proc_findnode(ptr);
|
2018-08-19 02:00:23 +02:00
|
|
|
if (node == NULL)
|
2013-12-12 16:21:55 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Invalid path \"%s\"\n", relpath);
|
2013-12-12 16:21:55 +01:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
/* If the node exists, it is the name for a read-only file or
|
|
|
|
* directory.
|
|
|
|
*/
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-12-15 17:31:07 +01:00
|
|
|
if (node->dtype == DTYPE_FILE)
|
|
|
|
{
|
2015-10-11 19:39:29 +02:00
|
|
|
buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR;
|
2013-12-15 17:31:07 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-11 19:39:29 +02:00
|
|
|
buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR;
|
2013-12-15 17:31:07 +01:00
|
|
|
}
|
2013-12-12 16:21:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-08-12 15:26:20 +02:00
|
|
|
#endif /* CONFIG_FS_PROCFS_EXCLUDE_PROCESS */
|
2013-12-12 16:21:55 +01:00
|
|
|
#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS */
|