[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Noob libssh question


I've made an Objective-C class called RemoteAccess to encapsulate all ssh
functionality. I've attached it to this note.


On Thu, Feb 6, 2014 at 3:49 PM, craig and heather <calhjh@xxxxxxxxx> wrote:

> Hello,
>
> I am using libssl to execute simple C programs between raspberry pi's.
> These programs are simple SDL graphics applications similar to that listed
> below that don't write anything to stderr (unless there is an error) or
> stdout.
>
> I am also doing some remote file creation and deletion using the same
> libssl functionality.
>
> When I remotely execute commands such as "touch runfile" or "rm runfile" I
> can see 0 bytes are returned from ssh_channel_read function as would be
> expected. However whenever I run one of my little C programs
> ssh_channel_read always returns -2 but the program runs successfully on the
> remote system.
>
> Is there something I need to do in my C programs to satisfy
> ssh_channel_read?
>
> Thanks for looking
>
>
> /*
>  * A Smart Screen Module
>  *
>  * Sets the entire screen to a specified RGB color
>  * Typical Call:
>  *      colorscreen 0 255 0
>  *
>  * Concept and Implementation by: Craig A. Lindley
>  * Last Update: 01/30/2014
>  */
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/stat.h>
> #include <sys/types.h>
>
> #include "SDL/SDL.h"
>
> #define RUN_FILE_NAME "runfile"
> #define BUSY_FILE_NAME "busy"
>
> // Check for file existance
> int file_exists(char *filename) {
>
>     struct stat buffer;
>     return (stat (filename, &buffer) == 0);
> }
>
> int main (int argc, char* args[]) {
>
>     if (argc != 4) {
>         fprintf(stderr, "Wrong number of arguments\n");
>         return -1;
>     }
>
>     // Extract RGB values from the command line arguments
>     int red   = atoi(args[1]);
>     int green = atoi(args[2]);
>     int blue  = atoi(args[3]);
>
>     // Range check the specified color values
>     if ((red   < 0) || (red   > 255) ||
>         (green < 0) || (green > 255) ||
>         (blue  < 0) || (blue  > 255)) {
>         fprintf(stderr, "Color values in range 0 <= value < 256\n");
>         return -1;
>     }
>
>     // Create the busy file
>     FILE *pFile = fopen (BUSY_FILE_NAME,"w");
>     if (pFile != NULL) {
>         fclose(pFile);
>     }    else    {
>         fprintf(stderr, "Could not create busy file\n");
>         return -1;
>     }
>
>     putenv("SDL_FBDEV=/dev/fb1");
>     putenv("SDL_VIDEODRIVER=fbcon");
>
>     // Start SDL
>     SDL_Init(SDL_INIT_VIDEO);
>
>     // Turn off cursor
>     SDL_ShowCursor(SDL_DISABLE);
>
>     const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
>
>     int width  = videoInfo->current_w;
>     int height = videoInfo->current_h;
>     uint8_t bpp = videoInfo->vfmt->BitsPerPixel;
>
>     // Set up screen
>     SDL_Surface *screen = SDL_SetVideoMode(width, height, bpp,
> SDL_SWSURFACE);
>     if (!screen) {
>         fprintf(stderr, "SDL_SetVideoMode failed\n");
>         return -1;
>     }
>     // Create the specified color
>     uint32_t color = SDL_MapRGB(screen->format, red, green, blue);
>
>     // Create rect the size of the screen
>     SDL_Rect rect = {0, 0, width, height};
>
>     // Fill the screen with the specified color
>     SDL_FillRect(screen, &rect, color);
>
>     // Update Screen
>     SDL_Flip(screen);
>
>     // Pause
>     SDL_Delay(1000);
>
>     // Wait until runfile is gone to terminate
>     while (file_exists(RUN_FILE_NAME)) {
>         SDL_Delay(50);
>     }
>
>     // Delete the busy file
>     if (remove(BUSY_FILE_NAME) != 0) {
>         fprintf(stderr, "Error deleting busy file\n");
>     }
>
>     // Quit SDL
>     SDL_Quit();
>
>     return 0;
> }
>
>
> --
> Craig Lindley
>
> If you're one in a million, there are now seven thousand people exactly
> like you.
>



-- 
Craig Lindley / Heather Hubbard

New Recordings: craigandheather.net/cnmpage.html
Latest CD: craigandheather.net/songsilike2013cd.html

Personal Website: craigandheather.net
Business Website: clockwork.craigandheather.net
Phone: (719) 495-1873
Cell: (719) 502-7925

If you're one in a million, there are now seven thousand people exactly
like you.

Attachment: RemoteAccess.m
Description: Binary data


Follow-Ups:
Re: Noob libssh questionAlan Dunn <amdunn@xxxxxxxxx>
References:
Noob libssh questioncraig and heather <calhjh@xxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org