Go Back   The macosxhints Forums > OS X Help Requests > UNIX - Newcomers



Reply
 
Thread Tools Rate Thread Display Modes
Old 04-29-2003, 06:29 PM   #1
eldwin
Prospect
 
Join Date: Apr 2003
Posts: 9
Newbie with some questions

Hello all,

I'm new to the mac / unix world. I recently just purchased a powerbook 12 inch and installed the developer tools.

I have a few questions:

When i am in the unix terminal, I've logged into unix as the root user and i get the message: tcsh: cannot open /etc/termcap
tcsh: using dumb terminal settings.

also, i'm using gcc and i can compile and make just fine, but when i'm running my program i get a: terminal database is inaccessible.

The code works because i've tested it in linux. What i'm doing is writing and reading from files (.txt and .dat.) One of the kids in school said in might be a permissions problem.

I would apreciate any and all advice on this matter.

Eldwin
eldwin is offline   Reply With Quote
Old 04-30-2003, 02:02 AM   #2
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
details needed

How about some more details of what you are doing?
Are you by any chance using a xterm under X Windows? (If so, this query is more suited for the X Windows section of the forums.)
Does your program make use of a curses-based user interface?
If you are 'root', then it is very unlikely that you are having permission problems.
The more basic problem is that something in the software you are using (your own program or the terminal it is running in) is looking for the file /etc/termcap. This file does not exist on a standard OS X system.

Last edited by hayne; 04-30-2003 at 02:04 AM.
hayne is offline   Reply With Quote
Old 04-30-2003, 04:12 AM   #3
eldwin
Prospect
 
Join Date: Apr 2003
Posts: 9
I'm not sure what you mean by xterm and X window.

I'm in a software engineering class and we've put together a text based role playing game.

During execution of the program, you are required to create or choose a previously created player. (Both will require to read info from a .txt file and .dat file.) The program does write to file properly, but it bails out when trying to read from file.

Like i said, it works on Linux as far as reading, writing, playing the game.

I'm just unfamiliar with these error messages.

Thanks for your help

Eldwin
eldwin is offline   Reply With Quote
Old 04-30-2003, 08:22 AM   #4
sao
Moderator
 
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
Quote:
eldwin wrote:
When i am in the unix terminal, I've logged into unix as the root

Can you give us more info on how you do it?
sao is offline   Reply With Quote
Old 04-30-2003, 08:57 AM   #5
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
Terminal

Quote:
Originally posted by eldwin
I'm not sure what you mean by xterm and X window.

So then, can I assume that you are using the "Terminal" application that is suppled by Apple under the Application/Utilities folder?

Quote:
I'm in a software engineering class and we've put together a text based role playing game.

Tell us what the interaction with the game is like. Did you write this part of the game or were you supplied with some of the software?

Quote:
Like i said, it works on Linux as far as reading, writing, playing the game.

Unfortunately, the code working on Linux merely means that it should be relatively easy to port to OS X - there is no guarantee of it automatically working without you making changes to the code to make it OS X compatible.

That is why I asked above about the user-interface of the game. A program with straight text-input from a prompt and straight text-output will work without changes on any UNIX system. But if you do anything fancy in the user-interface, like positioning text at a certain place on the screen (as opposed to just letting it scroll up in the Terminal) then you have to be careful to avoid system dependencies. It sounds like some part of your program has such system dependencies, otherwise it wouldn't be looking for the file /etc/termcap. This may be a library that you are linking against - not necessarily just the code that you wrote.

Here's a test program, just to check that your basic input & output is working.
Try compiling and running this program and let us know what happens with it.
(Not sure if you are using C or C++, so I stuck to plain C.)
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
    printf("Hello Eldwin\n");
    printf("Enter an integer:\n");
    int num;
    if (scanf("%d", &num) != 1)
    {
        fprintf(stderr, "Bad input\n");
        exit(1);
    }
    FILE *fp = fopen("junk.txt", "w");
    if (fp == 0)
    {
        fprintf(stderr, "Can't open file for writing\n");
        exit(1);
    }
    fprintf(fp, "%d\n", num);
    fclose(fp);
    printf("Your number was written to the file \"junk.txt\"\n");
    return 0;
}
hayne is offline   Reply With Quote
Old 05-03-2003, 03:59 AM   #6
eldwin
Prospect
 
Join Date: Apr 2003
Posts: 9
I've narrowed down the problem to reading and writing from/to binary .dat files.
In an attempt to prevent hacking of the game, we stored all the info of players/monsters/equipment in binary.dat files.

Obviously when someone opens one of these files up in a notepad, its going to look like a bunch of garbage.


As far as input, its just taking straight text input and displaying straight text output.
eldwin is offline   Reply With Quote
Old 05-03-2003, 04:09 AM   #7
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
answers?

You still haven't answered some of the questions I asked.
- are you using the Terminal program from Utilities?
- are you linking with any libraries?

What exactly are the problems you are having with these binary files? What does the reading & writing of binary files have to do with termcap - or are we now talking about a different problem?
hayne is offline   Reply With Quote
Old 05-03-2003, 02:40 PM   #8
eldwin
Prospect
 
Join Date: Apr 2003
Posts: 9
Ok when I start Darwin (yes it is a terminal from utilities), I type in 'login' and enter my user name and password.

After I do so, I get the file/etc/termcap line.

The folder, where the source files are located, are on the desktop.

I can compile the program using the makefile.

The program does start up and runs until it is required to read from the .dat file.

BTW, What is termcap?

Again i appreciate your help on this matter.

Eldwin
eldwin is offline   Reply With Quote
Old 05-03-2003, 03:24 PM   #9
djhyp3rion
Prospect
 
Join Date: Apr 2003
Location: Turn...around...
Posts: 34
Maybe there's a command in your ~/.tcsh that's trying to access the /etc/termcap. Just a suggestion...
__________________
-Phil
iBook G3 800 / 256MB / OS X 10.2
Macintosh SE 68k 7.5 MHz / 4MB / OS 6.08 (LOL)
djhyp3rion is offline   Reply With Quote
Old 05-03-2003, 07:04 PM   #10
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
Quote:
Ok when I start Darwin (yes it is a terminal from utilities), I type in 'login' and enter my user name and password

Whoah - slow down a minute. Let's start from the point where you are logged on your Mac. I'm assuming you are typing on the keyboard of the Mac - not doing a remote login to a Mac from some other machine. Ok then you double-click on Terminal in the Utilities folder and a new Terminal window opens. You don't need to enter your username & password in this window since you are already logged into the Mac. Does this correspond with what you are doing? You make it sound different when you talk about typing your name & password after mentioning Terminal.
(added afterwards:) Oh - now I see that you said that you type in the command 'login'. Don't do that - you are already logged in. (I tried typing 'login' as you do and I see that same error about termcap - strange - I'll investigate why this happens but anyway, just avoid the 'login' and all should be well.)

Quote:
After I do so, I get the file/etc/termcap line.

If you are saying that you get an error message about termcap after starting a new Terminal window, this definitely means that djhyp3rion is right - you have something in your "dot" files (e.g. ~/.cshrc, ~/.tcshrc, ~/.login, etc) that is causing this. It would be something that you added yourself as there is nothing like that there normally. So edit those files and remove anything suspicious by putting a comment character (#) at the start of the lines.

Quote:
The program does start up and runs until it is required to read from the .dat file.

And then what happens?

Quote:
BTW, What is termcap?

Your answer is here: http://www.google.com/search?q=termcap

Last edited by hayne; 05-03-2003 at 07:14 PM.
hayne is offline   Reply With Quote
Old 05-03-2003, 07:44 PM   #11
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
FWIW, this condition can be invoked thusly:
Code:
# normal login

% echo $TERM
vt100

% setenv TERM network
tcsh: Cannot open /etc/termcap.
tcsh: using dumb terminal settings.

# bork'd
__________________
On a clear disk, you can seek forever.
mervTormel is offline   Reply With Quote
Old 05-03-2003, 09:10 PM   #12
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
TERM=network

Right. So it seems (I looked at the source for tcsh) that this is partly a case of a bad error message. The code is using the function 'tgetent' which queries the terminfo database (which is what replaces /etc/termcap on OS X - and many other UNIX variants).
Since for some reason the environment variable TERM is set to "network" when the /usr/bin/login program is run, it is looking for a terminfo entry for "network" and such doesn't exist. The tcsh code then complains about /etc/termcap not existing - which is a bogus error message.

All the above was perhaps not of interest to anyone but myself - but the bottom line regarding the original poster's problem remains the same:
Don't use the 'login' command when you are already logged in.
hayne is offline   Reply With Quote
Old 05-03-2003, 09:32 PM   #13
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
thank you, sir.
mervTormel is offline   Reply With Quote
Old 05-06-2003, 10:03 PM   #14
WillyT
Major Leaguer
 
Join Date: Jan 2002
Location: Midwest Not quite Normal
Posts: 416
Not just login?

Unless su calls login.

Code:
[dreamersound:~] williamt% su root
Password:
_su: Cannot open /etc/termcap.
_su: using dumb terminal settings.
Well I always wondered about that and now I know. Thanks guys.
__________________
I have a Reason3 not to be grumpy and now I have a Rosegarden that works.
Willy
WillyT is offline   Reply With Quote
Old 05-06-2003, 10:20 PM   #15
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
su

I don't see that problem when I su to another user:

su fred

I don't have root enabled, so can't try that but maybe you can try su-ing to some other user than root to see if this is only a difficulty with root.
hayne is offline   Reply With Quote
Old 05-06-2003, 10:58 PM   #16
WillyT
Major Leaguer
 
Join Date: Jan 2002
Location: Midwest Not quite Normal
Posts: 416
Every user it seems.

Code:
[dreamersound:~] williamt% su tester
Password:
_su: Permission denied
_su: Trying to start from "/Users/tester"
_su: Cannot open /etc/termcap.
_su: using dumb terminal settings.
[dreamersound:~] tester% exit
exit
[dreamersound:~] williamt% su geraldin
Password:
_su: Permission denied
_su: Trying to start from "/Users/geraldin"
_su: Cannot open /etc/termcap.
_su: using dumb terminal settings.
[dreamersound:~] geraldin%
I understand the "Permission denied" as all users home dirs are 700 so the pwd can't see my home and it has to change.
__________________
I have a Reason3 not to be grumpy and now I have a Rosegarden that works.
Willy
WillyT is offline   Reply With Quote
Old 05-06-2003, 11:11 PM   #17
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
what about 'su -' ?

What happens if you use 'su -' instead of 'su' ?
E.g.:
su - fred
This effectively does a login as that user.
You might be seeing this "termcap" problem with su due to your 700 permissions.
hayne is offline   Reply With Quote
Old 05-07-2003, 09:35 AM   #18
WillyT
Major Leaguer
 
Join Date: Jan 2002
Location: Midwest Not quite Normal
Posts: 416
Need .termcap

Here's the problem:
Code:
[dreamersound:~] williamt% setenv
HOME=/Users/williamt
SHELL=/bin/tcsh
USER=williamt
LANG=en_US
PATH=/sw/share/Geomview/bin:/sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/X11/bin
__CF_USER_TEXT_ENCODING=0x1F5:0:0
TERM=vt100-color
TERMCAP=���
TERM_PROGRAM=Apple_Terminal
TERM_PROGRAM_VERSION=81
...
The 3 ? all have a Diamond around them(char value 65533)(double byte chars?).

Yes and su - works for the Permission denied message.

So I put my .termcap and my .terminfo dir into the other users home dir and I can su - cleanly.

The TERM=vt100-color thing is part of the color ls mod. Which now works for each user. (dang its hard to remember all the little hacks we do)

I found this when I logged in as tester and started Terminal.app and up pops the "Cannot open /etc/termcap" message. I think I remember fighting this back when I first installed Jaguar too.

Thanks
__________________
I have a Reason3 not to be grumpy and now I have a Rosegarden that works.
Willy
WillyT is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 10:40 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.