Skip to content

Implemented lsipc #253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2025
Merged

Implemented lsipc #253

merged 1 commit into from
Apr 1, 2025

Conversation

koutheir
Copy link
Contributor

@koutheir koutheir commented Mar 13, 2025

Dependencies I had to do:

Closes #19.

@koutheir
Copy link
Contributor Author

FYI, in order to test the tool, I had to artificially create some semaphores and message queues on my system. Here follows are two C programs I wrote for just that. The programs create the semaphores and the message queues, then they wait indefinitely for Ctrl+C before deleting the objects and terminating.

// sem.c

#include <assert.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <sys/sem.h>
#include <sys/stat.h>
#include <unistd.h>

static int exit_now = 0;

void sigint_handler(int signal) { exit_now = 1; }

int main() {
    signal(SIGINT, sigint_handler);

    int s = semget(IPC_PRIVATE, 3, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
    assert(s != -1);

    printf("# Semaphores created.\n");

    semctl(s, 0, SETVAL, (int)7);
    semctl(s, 1, SETVAL, (int)0);
    semctl(s, 2, SETVAL, (int)500);

    printf("# Semaphores configured.\n");

    while (!exit_now) {
        usleep(1000 * 1000);
    }

    semctl(s, 0, IPC_RMID);

    printf("# Semaphores deleted.\n");

    return 0;
}
// msq.c

#include <assert.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <sys/msg.h>
#include <sys/stat.h>
#include <unistd.h>

struct msgbuf {
    long mtype;     /* message type, must be > 0 */
    char mtext[32]; /* message data */
};

static int exit_now = 0;

void sigint_handler(int signal) { exit_now = 1; }

int main() {
    signal(SIGINT, sigint_handler);

    int q = msgget(IPC_PRIVATE, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
    assert(q != -1);

    printf("# Message queue created.\n");

    struct msgbuf msg0 = {7, "Hello!"};
    msgsnd(q, &msg0, 32, 0);
    msgsnd(q, &msg0, 32, 0);
    msgsnd(q, &msg0, 32, 0);

    printf("# Message queue configured.\n");

    while (!exit_now) {
        usleep(1000 * 1000);
    }

    msgctl(q, IPC_RMID, NULL);

    printf("# Message queue deleted.\n");

    return 0;
}

@sylvestre
Copy link
Contributor

smartcols-sys: Failed to find 'libsmartcols/libsmartcols.h'. Please make sure the C header files of libsmartcols are installed and accessible: Kind(NotFound)

Could you please add it to the CI ? thanks!

@koutheir
Copy link
Contributor Author

I added sequences like this to the CI configuration:

- run: sudo apt-get update --quiet
- run: sudo apt-get install --quiet --no-install-recommends --assume-yes libclang-dev libc6-dev libsmartcols-dev

@sylvestre
Copy link
Contributor

This branch has conflicts that must be resolved

could you please fix that ? :)
thanks

@koutheir
Copy link
Contributor Author

could you please fix that ? :)

Done.

@koutheir
Copy link
Contributor Author

koutheir commented Mar 17, 2025

@sylvestre, I still see failures in CI for Windows and MacOS X. Isn't this project Linux-specific?

@koutheir koutheir force-pushed the main branch 5 times, most recently from b600653 to 2d3e3cb Compare March 22, 2025 01:55
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces a new lsipc command along with its supporting modules and configuration updates for listing IPC facilities. Key changes include:

  • Implementation of core functionality in multiple modules (utils, smartcols, message_queue, display, column).
  • Addition of new Cargo.toml configuration and documentation (lsipc.md) for the command.
  • Updates to CI workflows and top‑level project configuration to include lsipc.

Reviewed Changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/uu/lsipc/src/utils.rs Utility functions for system page size, local time conversion, and file I/O.
src/uu/lsipc/src/smartcols.rs Initialization and operations for smartcols table handling.
src/uu/lsipc/src/message_queue.rs Parsing and processing of System V IPC message queue information.
src/uu/lsipc/src/main.rs Command entry point invoking the new lsipc functionality.
src/uu/lsipc/src/errors.rs Custom error types and error‐generating helper functions.
src/uu/lsipc/src/display.rs Formatting utilities for time, size, and permissions display.
src/uu/lsipc/src/column.rs Definitions for column metadata and output customization.
src/uu/lsipc/lsipc.md User documentation for the lsipc command.
src/uu/lsipc/Cargo.toml Package configuration for the new lsipc crate.
Cargo.toml Top‑level workspace manifest updated to include lsipc.
.github/workflows/ci.yml CI configuration updated to install additional OS dependencies as needed.
Files not reviewed (1)
  • src/uu/lsipc/after-help.txt: Language not supported
Comments suppressed due to low confidence (1)

src/uu/lsipc/src/message_queue.rs:285

  • [nitpick] Consider using a more descriptive variable name or adding an inline comment to explain the conversion and filtering logic for msqid to improve code readability.
            .filter(|(msqid, _stat)| c_uint::try_from(*msqid).is_ok_and(|msqid| msqid == id))

@sylvestre sylvestre merged commit fac8a0b into uutils:main Apr 1, 2025
13 checks passed
Copy link

codecov bot commented Apr 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (07d7534) to head (9bb2bb3).
Report is 11 commits behind head on main.

Additional details and impacted files
@@     Coverage Diff     @@
##   main   #253   +/-   ##
===========================
===========================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement program lsipc
2 participants